【问题标题】:Currency symbol on wrong side货币符号在错误的一边
【发布时间】:2020-06-07 05:33:01
【问题描述】:

RichTextBox 中显示价格。它接受代表价格的double 值并将其显示为字符串。

double priceDisplayed = 0.00;
richTextBox_itemPrice.Text = priceDisplayed.ToString("C", new CultureInfo("en-AU"));

上面的代码导致在右轴上用货币显示价格:

0.00$

这是为什么?检查类似的例子,上面的代码似乎应该在 LHS 上显示货币符号。

【问题讨论】:

  • 在分配给richTextBox_itemPrice.Text 之前是否将文本渲染到字符串变量来解决问题?
  • 在 dot net fiddle 中为我呈现为 $0.00。您能否提供有关执行环境的更多信息?
  • @Gavin,我试过了,同样的问题。
  • @IanMercer 这是一个针对 .NET Framework 4.6.1 的 WinForms 应用程序。尝试了调试和发布版本。使用 VS 2017 构建,在 Windows 10 上运行。
  • 真的很奇怪。你的new CultureInfo("en-AU").NumberFormat.CurrencyPositivePattern不是0吗? (it should be 0 特别是考虑到您当前的文化..)有一个类似的案例here 使用不同的框架和机器,也许尝试使用CultureInfo.GetCultureInfo("en-AU")

标签: c# .net currency cultureinfo


【解决方案1】:

这真的很奇怪,正如评论中提到的,你的机器上一定有一些文化-冲突。

与此同时,您可以在TextChanged 活动中尝试这样的事情:

private void richTextBox_itemPrice_TextChanged(object sender, EventArgs e)
{
    string text = richTextBox_itemPrice.Text;
    if (richTextBox_itemPrice.Text.Contains("$")) 
    {
        text = text.Replace("$","");
    }

    richTextBox_itemPrice.Text = "$" + text;
}

并将字段初始化为richTextBox_itemPrice.Text = "$";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 2017-06-13
    • 2012-08-12
    相关资源
    最近更新 更多