如何在 C# 中将 int 格式化为货币?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/430458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 03:04:42  来源:igfitidea点击:

How to format an int as currency in C#?

c#formattingcurrency

提问by Ken

I want to format an int as a currency in C#, but with no fractions. For example, 100000 should be "$100,000", instead of "$100,000.00" (which 100000.ToString("C") gives).

我想在 C# 中将 int 格式化为货币,但没有分数。例如,100000 应该是“$100,000”,而不是“$100,000.00”(由 100000.ToString("C") 给出)。

I know I can do this with 100000.ToString("$#,0"), but that's $-specific. Is there a way to do it with the currency ("C") formatter?

我知道我可以用 100000.ToString("$#,0") 做到这一点,但这是特定于 $ 的。有没有办法用货币(“C”)格式化程序来做到这一点?

采纳答案by jfs

Use format "C0".

使用格式“C0”。

回答by Henry Vilinskiy

Possible to use n0 which provide commas like 1,234. Currency sign won't be there

可以使用 n0 提供像 1,234 这样的逗号。货币符号不会出现

回答by Suraj Shrestha

try

尝试

using System.Globalization
@string.Format(new CultureInfo("en-IN"), "{0:c}", moneyvalue)

wil show the format in Rs.

将以卢比显示格式。