C#ToString(“C”)将小数转换为货币值而不是美元

时间:2021-03-17 17:08:13

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

我正在将double值转换为货币字符串格式,并使用井号符号货币转换为字符串。它依赖于文化吗?

3 个解决方案

#1


2  

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.

如果您总是希望使用特定的区域设置,如果您的服务器目标托管在不同的时区等,则可能需要这样做... ToString()可以提供CultureInfo参数。

How to convert string to double with proper cultureinfo

如何使用适当的cultureinfo将字符串转换为double

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?

从当前访问者那里获取CultureInfo并根据它设置资源?

#2


1  

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!

希望这可以帮助!如果没有让我知道,我将删除答案(我必须使用答案,因为我无法在50代表评论,否则我会在回答之前使用评论更清晰)干杯!

#3


-1  

Control Panel > Region > Formats > Advanced

C#ToString(“C”)将小数转换为货币值而不是美元

#1


2  

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.

如果您总是希望使用特定的区域设置,如果您的服务器目标托管在不同的时区等,则可能需要这样做... ToString()可以提供CultureInfo参数。

How to convert string to double with proper cultureinfo

如何使用适当的cultureinfo将字符串转换为double

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?

从当前访问者那里获取CultureInfo并根据它设置资源?

#2


1  

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!

希望这可以帮助!如果没有让我知道,我将删除答案(我必须使用答案,因为我无法在50代表评论,否则我会在回答之前使用评论更清晰)干杯!

#3


-1  

Control Panel > Region > Formats > Advanced

C#ToString(“C”)将小数转换为货币值而不是美元