如何小数使用C#每次后显示两个数字? [英] How to display two digits after decimal every time using C#?
本文介绍了如何小数使用C#每次后显示两个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个过程,其中客户要我总是以两位小数要么有值与小数与否
I have a process, in which client want me to always display amount with two decimals either have value with decimal or not
例如:如果 17 ,然后我想显示17.00,如果17.2然后我想显示17.20
或者,如果17.2033然后我想显示17.20我曾尝试的String.Format({0:##},rec.Rate)
example: if 17 then i want to display "17.00" and if 17.2 then i want to display "17.20"
or if 17.2033 then i want to display "17.20" i have tried String.Format("{0:.##}", rec.Rate)
它不工作,请大家帮帮我,我该怎么办呢..在此先感谢
it does not works, please help me how can i do it.. thanks in advance
推荐答案
尝试
double num=17.2;
string str=num.toString("0.00");
或本之一。
double num=17.2;
string str=num.toString("N2");
这篇关于如何小数使用C#每次后显示两个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文