1

I need to convert a float number into 2 decimal format.I have tried Math.round(AmountSpent1,2)
This is my code:

float AmountSpent1 = float.Parse(FixedAmount);
Math.Round(AmountSpent1, 2);
Anto Robinson
  • 463
  • 5
  • 12
Por Weiting
  • 167
  • 3
  • 5
  • 15
  • See answer here: http://stackoverflow.com/questions/441600/write-a-number-with-two-decimal-places-sql-server – Phil Aug 13 '13 at 02:06

2 Answers2

2
float AmountSpent1 = float.Parse(FixedAmount);
decimal m =Convert.ToDecimal(AmountSpent1);
decimal d = Math.Round(m, 2);
Samiey Mehdi
  • 9,184
  • 18
  • 49
  • 63
0

You could simply try this one

DecimalFormat df=new DecimalFormat("#.##");

For Example

float AmountSpent1 = float.Parse(FixedAmount);
System.out.println(df.format(AmountSpent1));

Anto Robinson
  • 463
  • 5
  • 12