c#中的十进制格式 [英] Decimal format in c#

查看:86
本文介绍了c#中的十进制格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我的情况是我有数字和小数...例如



7应转换为7.00

10应转换为10.00

54.43应为54.43



请给出最佳解决方案转换成上面的格式作为字符串.....如果你使用任何文化信息将更好...在c#

解决方案

HTTP: //stackoverflow.com/questions/164926/c-sharp-how-do-i-round-a-decimal-value-to-2-decimal-places-for-output-on-a-pa [ ^ ]


如果你尝试检查文档 [ ^ ] first。


你可以使用ToString,它更快。

  Int32  num1 =  7 ; 
UInt16 num2 = 10 ;
double num3 = 54 53 ;
string str1 = num1.ToString( 0.00\" );
string str2 = num2.ToString( 0.00\" );
string str3 = num3.ToString( 0.00\" );


Hello,
I have a situation where i have both numeric and decimals... For example

7 should be converted to 7.00
10 should be converted to 10.00
54.43 should be as 54.43

please give a best solution to convert into above format as a string..... it will be better if u use any cultre info... in c#

解决方案

http://stackoverflow.com/questions/164926/c-sharp-how-do-i-round-a-decimal-value-to-2-decimal-places-for-output-on-a-pa[^]


It will be better if you try checking the documentation[^] first.


You can use ToString, it is faster.

Int32 num1 = 7;
UInt16 num2 = 10;
double num3 = 54.53;
string str1 = num1.ToString("0.00");
string str2 = num2.ToString("0.00");
string str3 = num3.ToString("0.00");


这篇关于c#中的十进制格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆