gpt4 book ai didi

c# - 使用 CultureInfo 将 USD 符号替换为 -

转载 作者:太空宇宙 更新时间:2023-11-03 19:38:27 25 4
gpt4 key购买 nike

我目前正在使用此代码来删除 US symbol 并使数字显示为negative

我使用的代码是:

public strNegative = "-";

string Result = TrnAmount
.ToString("C3", new CultureInfo("en-US"))
.Replace("$", strNegative);

但是结果显示带括号:

Result = "(-5)"

当要求的格式是

Result = "-5"

最佳答案

欢迎。要获得负数,只需将数字乘以 -1。然后使用 N3 as a string format如果您想获得一般数字而不是货币格式。

float TrnAmount = 2.5684155f;
string result = (-1 * TrnAmount).ToString("N3");
Console.WriteLine(result); //This will give you -2.568 as a result

关于c# - 使用 CultureInfo 将 USD 符号替换为 -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58198401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com