货币格式错误

时间:2019-01-12 21:29:35

标签: asp.net-core .net-core

我已经做到了...

[HttpGet("method")]
    public IEnumerable<object> GetStuff() =>
        repos.FetchStuff()
            .Select(c => new
            {
                val = string.Format("{0:C}", c.Rate)
            });

并且将货币格式设置为¤8.00

好吧,我想知道那是什么货币?!

如何使它显示英镑符号?

2 个答案:

答案 0 :(得分:1)

如上所述,您必须设置CultureInfo

示例:

using System;
using System.Globalization;

public class Program
{
    public static void Main()
    {
        var total = 10.99;
        var numFormat = new CultureInfo("en-GB").NumberFormat;
        Console.WriteLine(total.ToString("c", numFormat));          
    }
}

结果:£10.99

答案 1 :(得分:1)

您可以尝试以下一种方法:

[HttpGet("method")]
public IEnumerable<object> GetStuff() =>
    repos.FetchStuff()
        .Select(c => new
        {
            val = c.Rate.ToString("c" , new CultureInfo("en-GB").NumberFormat)
        });