Friday, December 5, 2014

Specify the English culture when casting a decimal to a string and then splitting on the decimal point as there is no decimal point in Spanish counterpart.

public static string CovertPaymentAmountToCardinalCommerceFriendlyString(Decimal
      paymentAmount)
{
   string decimalAsString = Math.Round(paymentAmount, 2).ToString(new
         System.Globalization.CultureInfo("en"));
   if (decimalAsString.Contains("."))
   {
      string[] paymentAmountArray = decimalAsString.Split(".".ToCharArray());
      if (paymentAmountArray[1].Length == 1)
      {
         return paymentAmountArray[0] + paymentAmountArray[1] + "0";
      } else {
         return paymentAmountArray[0] + paymentAmountArray[1].Substring(0, 2);
      }
   } else {
      return decimalAsString + "00";
   }
}

 
 

The Spanish stringification would have a comma in it in lieu of a period. :(

No comments:

Post a Comment