【问题标题】:Format price in Danish with curency symbol on right以丹麦语格式化价格,右侧有货币符号
【发布时间】:2013-07-21 14:18:10
【问题描述】:

如何在 Eval() 方法中为丹麦语价格和右侧的货币符号格式化价格 i C#?

我的 .aspx 页面中有以下内容来显示价格:

<td class="text-right price-col"><%# Eval("Price", "{0:c}") %></td>

但这会将价格显示为例如韩币。 79,00 ..我想要的是79,00 kr.

我看到这篇帖子Changing Currency Symbol location in System.Globalization.NumberFormatInfo 并在代码隐藏中添加了这个方法,这给了我想要的结果:

<td class="text-right price-col"><%# PriceFormat(79) %></td>

protected string PriceFormat(decimal price) {
        System.Globalization.CultureInfo danish = new System.Globalization.CultureInfo("da-DK");
        danish = (System.Globalization.CultureInfo)danish.Clone();
        // Adjust these to suit
        danish.NumberFormat.CurrencyPositivePattern = 3;
        danish.NumberFormat.CurrencyNegativePattern = 3;
        decimal value = price;
        string output = value.ToString("C", danish);

        return output;
    }

但是我可以使用 PriceFormat 方法和 Eval() 方法来获得正确的价格作为参数,或者修改 Eval() 方法中的格式来做同样的事情吗? 在示例中,我只是插入了一个静态值作为参数 (79)。

【问题讨论】:

    标签: c# localization currency


    【解决方案1】:

    Eval 返回一个object,因此您可以将其转换为decimal 并将其作为参数传递给您的PriceFormat 方法:

    <%# PriceFormat((decimal)Eval("Price")) %>
    

    【讨论】:

    • 谢谢 :) 我将 PriceFormat 移到了单独的类 Common,因此可以在其他文件中重用该方法:
    猜你喜欢
    • 1970-01-01
    • 2012-01-29
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多