帮助浮动格式化 [英] Help with float formatting
本文介绍了帮助浮动格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
使用C#。
需要小帮助。虽然它显示的很小,我无法弄明白。
我有一个计算结果将结果返回浮动为
Hello,
Using C#.
Need small help. Though it is showing as small i am unable to figure it out.
I am having a calculation which returns result into float as
43.518265
我想格式化为43.52而不是44.0或44.6或44.60
我试过了
I would like to format it as 43.52 not 44.0 or 44.6 or 44.60
I have tried
Math.Round(MedicaidFee, 1, MidpointRounding.AwayFromZero)
Math.Round(MedicaidFee)
Math.Round(MedicaidFee)
Math.Round((Math.Round(CareSourceFee * 20, MidpointRounding.AwayFromZero) / 20) 2)
没什么好的。
任何人都可以帮我这样做。
先谢谢。
我尝试过:
Nothing wokring out.
Can anyone help me for the same.
Thanks In advance.
What I have tried:
Math.Round(MedicaidFee, 1, MidpointRounding.AwayFromZero)
Math.Round(MedicaidFee)
Math.Round((Math.Round(CareSourceFee * 20, MidpointRounding.AwayFromZero) / 20) 2)
推荐答案
如果您打算将其格式化以进行显示,您可以这样做:
If your intent is to format it for displaying, you can simply do:
MedicaidFee.ToString(".00")
如果你想在尝试中实际舍入值,你可以这样做:
If you want to actually round the value as in your attempts, you could do:
Math.Round(MedicaidFee * 100) / 100;
Hi, Have you tried this code:
<pre lang="c#">
float a = 43.518265F;
float b = (float)Math.Round(a, 2);
祝你好运
Best regards
这篇关于帮助浮动格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文