格式化C#中的逗号和小数点的数字(asp.net MVC3) [英] format a number with commas and decimals in C# (asp.net MVC3)

查看:367
本文介绍了格式化C#中的逗号和小数点的数字(asp.net MVC3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示用逗号和小数点的数字。

例如:
案例1:十进制数为432324(这个没有逗号或小数点)
需要显示为 432,324.00 结果
但不是432324

案例2:十进制数为2222222.22(这没有逗号)
需要显示为 2,222,222.22

我试过的ToString(#,## 0。##)。但它不是格式化


解决方案

  INT数= 1234567890;
Convert.ToDecimal(数字)的ToString(#,## 0.00);

您将得到的结果 1,234,567,890.00

I Need to display a number with commas and decimal point.

Eg: Case 1 : Decimal number is 432324 (This does not have commas or decimal Points) Need to display it as 432,324.00
but not 432,324

Case 2 : Decimal number is 2222222.22 (This does not have commas) Need to display it as 2,222,222.22

I tried ToString("#,##0.##"). But It is Not Formatting it

解决方案

int number = 1234567890;
Convert.ToDecimal(number).ToString("#,##0.00");

You will get the result 1,234,567,890.00.

这篇关于格式化C#中的逗号和小数点的数字(asp.net MVC3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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