本文介绍了String.Format整数以在丹麦文化中使用带十进制值的千位分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串 totalPRice ,其中包含这样的值 1147,5 我要两件事.
1)将值四舍五入,以使
后始终有两位数字2)在该字符串中使用千位分隔符,这样最终输出将是这样的 1.147,50
我已经尝试过类似的事情

I have a string totalPRice which holds a value like this 1147,5 I want two things.
1)round the value so that there is always two digits after ,
2)Implement thousands separator in this string, So that final out put will be some thing like this 1.147,50
I have tried some thing like this

String.Format("{0:0.00}", totalPRice)

它通过产生输出 1147,50 正确地满足了我的第一个要求.但是我的第二个要求落后.谁能告诉我如何实现这一目标?

It does my first requirement correctly by producing an output 1147,50.But I am way behind in my second requirement. Can any one tell me how I can achieve this?

注意:在丹麦文化中,.代表代表.

Note: In danish culture . stands for , and , stands for .

推荐答案

您可以参考标准数字格式字符串并使用

string.Format("{0:N2}", 1234.56)

如果丹麦语不是您的默认区域性,您也可以手动指定区域性:

You may also specify the culture manually, if danish is not your default culture:

var danishCulture = CultureInfo.CreateSpecificCulture("da-DK");
string.Format(danishCulture, "{0:N2}", 1234.56);

请参见 MSDNCultureInfo参考

这篇关于String.Format整数以在丹麦文化中使用带十进制值的千位分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 14:53