我有一个将十进制转换为字符串货币的方法
public static string ToCurrencyWithParentheses(this decimal initDecimal)
{
return initDecimal.ToString("C", CultureInfo.GetCultureInfo("en-US"));
}
我们最近在一个项目中从 .net48 切换到 .net6,我注意到该方法开始以不同的方式工作。在 .net48 上,我会将负数
-58.45
传递到方法中并得到 ($58.45)
,但现在在 .net6 上我得到 -$58.45
。
谁能告诉我如何修复该方法而不进行错误编码,以便正确处理数字?或者这是一个错误?
我无法通过谷歌搜索现成的解决方案。我尝试使用 string.Format() 而不是 ToString() 之类的东西,但没有任何效果。
将这些行添加到您的项目文件中:
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>