[英]Format Decimal String in C# using .ToString()
I have an amount stored in a decimal result
:我有一个存储在十进制
result
的金额:
Eg.例如。
decimal result = 1935698.27;
How can I format that to a String
using .ToString()
so that it looks like this: R 1 935 698,27
如何使用
.ToString()
将其格式化为String
,使其看起来像这样: R 1 935 698,27
It needs to do the following:它需要执行以下操作:
R
(take note of the space) to the front of the String
R
(注意空格)添加到String
的前面R 00 000 000 000,00
)R 00 000 000 000,00
).
.
with a ,
,
This formats according to the South African Rand currency format.此格式根据南非兰特货币格式进行设置。
This is what I have:这就是我所拥有的:
decimal result = 1935698.27;
string strResult = result.ToString("What should I put here?"); // Need help
// Expected strResult = "R 1 935 698,27"
Any help is much appreciated!任何帮助深表感谢!
This is built in - just use the South African culture and the currency format specifier .这是内置的 - 仅使用南非文化和货币格式说明符。
var result = 1935698.27m;
var ci = new CultureInfo("en-ZA");
var strResult = result.ToString("C", ci);
// strResult is R 1 935 698,27
See this fiddle .看到这个小提琴。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.