【发布时间】:2013-08-14 12:01:45
【问题描述】:
我需要将浮点数转换为 2 位十进制格式。我尝试过 Math.round(AmountSpent1,2)
这是我的代码:
float AmountSpent1 = float.Parse(FixedAmount);
Math.Round(AmountSpent1, 2);
【问题讨论】:
我需要将浮点数转换为 2 位十进制格式。我尝试过 Math.round(AmountSpent1,2)
这是我的代码:
float AmountSpent1 = float.Parse(FixedAmount);
Math.Round(AmountSpent1, 2);
【问题讨论】:
你可以试试这个
DecimalFormat df=new DecimalFormat("#.##");
举例
float AmountSpent1 = float.Parse(FixedAmount);
System.out.println(df.format(AmountSpent1));
【讨论】:
float AmountSpent1 = float.Parse(FixedAmount);
decimal m =Convert.ToDecimal(AmountSpent1);
decimal d = Math.Round(m, 2);
【讨论】: