C# ToString(“C”) converting the decimal to currenc

2019-09-21 08:55发布

I am converting a double value to currency string format and it gets converted string with pound symbol currency. Is it culture dependent?

3条回答
闹够了就滚
2楼-- · 2019-09-21 09:05

This probably isn't the best/most efficient way to do this, but have the decimal you want to show pounds converted into a string and just replace the dollar sign with the pound sign

decimal monies = 2.50m;
string moniesString = monies.ToString();
string moniesFormatted = string.Format("{0}£", moniesString);

again this most likely isn't the best or most efficient way to do so, but its a work around to avoid having to change your computer settings.

Hope this helps! If not let me know and I'll remove the answer(I had to use an answer because I can't comment under 50 rep, otherwise I would have used a comment to get some more clarity before answering) Cheers!

查看更多
叼着烟拽天下
3楼-- · 2019-09-21 09:19

If you always want to use a a specific locale, which may be desirable if your server target is hosted in a different timezone, etc... ToString() can be supplied with a CultureInfo argument.

How to convert string to double with proper cultureinfo

If you want to tailor it to the user's locale, You might be able to examine the request values:

Get CultureInfo from current visitor and setting resources based on that?

查看更多
走好不送
4楼-- · 2019-09-21 09:30
Control Panel > Region > Formats > Advanced

enter image description here

查看更多
登录 后发表回答