简体   繁体   English

String.format 根据 CurrentCulture 更改十进制变量

[英]String.format to change a decimal variable depending on CurrentCulture

I need to change the format of variable, depending on CurrentCulture我需要根据 CurrentCulture 更改变量的格式

Variable is a Decimal变量是十进制

This is my current change statement :这是我当前的更改声明:

 string auxst = String.Format(CultureInfo.CurrentCulture, "#,##0.00", variable);

I need to know what to put in the second parameter so that this happens:我需要知道在第二个参数中放什么,以便发生这种情况:

Variable = 150.465,1242345

If CurrentCulture is "es ES"(spain) ->  auxst = "150.465,1242345"

If CUrrentCulture is "en EN" ->  auxst = "150,465.1242345"

Thx for the help谢谢你的帮助

If you use CurrentCulture, do not specify it.如果您使用 CurrentCulture,请不要指定它。

You should use Decimal.ToString():您应该使用 Decimal.ToString():

Decimal variable = 15465.1242345M;
string auxst = variable.ToString("N");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM