Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 1.39 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Float value should have 2 decimals
  2. totalAmount += float.Parse(Amount[index].ToString());
  3.        
  4. if (totalAmount.ToString().Contains("."))
  5.         {
  6.             string[] b = totalAmount.ToString().Split('.');
  7.             Dollars = b[0].ToString().PadLeft(10, (char)48);
  8.             cents = b[1].ToString().PadRight(2, (char)48).Substring(0, 2);
  9.         }
  10.         else
  11.         {
  12.             Dollars = totalAmount.ToString().PadLeft(10, (char)48);
  13.             cents = "00";
  14.         }
  15.  
  16.         FormattedTotalAmounts = Dollars + cents; // Here i am getting the output as i said
  17.        
  18. if (totalAmount.ToString().Contains("."))
  19.     {
  20.         string[] b = totalAmount.ToString().Split('.');
  21.         Dollars = b[0].ToString().PadLeft(10, (char)48);
  22.         cents = b[1].ToString().PadRight(2, (char)48).Substring(0, 2);
  23.     }
  24.     else
  25.     {
  26.         Dollars = totalAmount.ToString("F2").PadLeft(10, (char)48);//Necessary change
  27.         cents = "00";
  28.     }
  29.  
  30.     FormattedTotalAmounts = Dollars + cents;
  31.        
  32. string totalAmountFormatted = totalAmount.ToString("F2");
  33.        
  34. String.Format("{0:0.00}", 756.4);
  35.        
  36. decimal t = 756.40m;
  37. MessageBox.Show(t.ToString("0.00"));
  38.        
  39. SomeVar.ToString("#,##0.00")
  40.        
  41. Decimal total;
  42. foreach (object oAmount in Amount)
  43. {
  44.    Decimal amount = (Decimal)oAmount;
  45.    total += amount;
  46. }
  47. String FormattedTotalAmounts = total.ToString("G");
  48.        
  49. String FormattedTotalAmounts = total.ToString("0000000000.00");