使用c#中的加号和减号将十进制格式化为货币

Bla*_*ell -1 c#

有没有办法格式化小数,使其显示为带有+或 - 符号的货币?

例如:

+ $ 5.00(大于零的加号)
$ 0.00(零没有符号)
- $ 5.00(减号小于零)

以下是我想要的但不确定如何合并货币:

var formattedprice = $"{price:+0;-#}"
Run Code Online (Sandbox Code Playgroud)

我通常使用C0作为货币或N0作为数字.

Ale*_*yov 5

class Program
{
    static void Main(string[] args)
    {
        var pos = 5m;
        var zero = 0m;
        var neg = -5m;

        var format = "+$0.00;-$0.00;$0.00";

        Console.WriteLine(pos.ToString(format));
        Console.WriteLine(zero.ToString(format));
        Console.WriteLine(neg.ToString(format));
    }
}
Run Code Online (Sandbox Code Playgroud)

而输出是

+$5,00
$0,00
-$5,00
Run Code Online (Sandbox Code Playgroud)

根据@ xxbbcc的评论,货币符号位置取决于区域设置,因此您必须按照更改格式.