C# ToString(“C”) converting the decimal to currency value pound instead of dollar

大兔子大兔子 提交于 2019-12-14 03:28:24

问题


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


回答1:


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?




回答2:


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:


Control Panel > Region > Formats > Advanced



来源:https://stackoverflow.com/questions/45600344/c-sharp-tostringc-converting-the-decimal-to-currency-value-pound-instead-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!