C#:格式化价值的字符串 [英] C#: Formating Price value string

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

问题描述

在C#中,我有一个双变量的价格与价值10215.24。我想说明与逗号后的价格有些digits.Can任何人都帮我做this.My预计产量10,215.24


解决方案

  myPrice.ToString(N2); 



这取决于你想要什么,你也不妨来显示货币符号:

  myPrice.ToString(C2); 



(数表示多少小数应使用的C或N之后)。
(C格式的数字作为货币字符串,其中包括一个货币符号)



要完全政治正确,你也可以指定CultureInfo的,应该是用了。


in C#,I have a double variable price with value 10215.24. I want to show the price with comma after some digits.Can anyone help me to do this.My expected output is 10,215.24

解决方案

myPrice.ToString("N2");

depending on what you want, you may also wish to display the currency symbol:

myPrice.ToString("C2");

(The number after the C or N indicates how many decimals should be used). (C formats the number as a currency string, which includes a currency symbol)

To be completely politically correct, you can also specify the CultureInfo that should be used.

这篇关于C#:格式化价值的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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