C#:格式化价格值字符串 [英] C#: Formatting Price value string
本文介绍了C#:格式化价格值字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C# 中,我有一个值为 10215.24 的双变量价格.我想在一些数字后用逗号显示价格.我的预期输出是 10,215.24
in C#,I have a double variable price with value 10215.24. I want to show the price with comma after some digits. 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");
(C 或 N 后面的数字表示应该使用多少个小数).(C 将数字格式化为货币字符串,其中包含货币符号)
(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)
为了在政治上完全正确,您还可以指定应该使用的 CultureInfo.
To be completely politically correct, you can also specify the CultureInfo that should be used.
这篇关于C#:格式化价格值字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文