question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StringFormat doesn't return the correct currency format

See original GitHub issue
  • .NET Core Version: 5
  • Windows version: Windows 10 Pro
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: No
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc…)? No

Problem description: Binding to a decimal value using the currency StringFormat (“c”) produces the wrong output for (en-US) culture with CurrencyNegativePattern=0.

Actual behavior: “-$123.45”

Expected behavior: “($123.45)”

Minimal repro: View Model

public class TestViewModel
{
    public decimal DecimalValue { get; set; } = -123.45M;
    public string FormattedValue
    {
        get
        {
            return DecimalValue.ToString("c");
        }
    }
}

XAML Binding

<Window.DataContext>
    <local:TestViewModel x:Name="vm"/>
</Window.DataContext>
<StackPanel>
    <StackPanel Margin="20">
        <TextBox Text="{Binding DecimalValue, StringFormat=c}"/>
        <TextBox Text="{Binding FormattedValue, Mode=OneWay}"/>
    </StackPanel>

    <StackPanel Margin="20">
        <TextBlock Text="{Binding DecimalValue, StringFormat=c}"/>
        <TextBlock Text="{Binding FormattedValue, Mode=OneWay}"/>
    </StackPanel>
</StackPanel>

Example Output image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dipeshmsftcommented, Aug 24, 2022

@DannyLee89 @miloush, as per my understanding we have reached to a conclusion on this issue, right ?? Is it alright to close this ?

0reactions
dipeshmsftcommented, Aug 24, 2022

Closing this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Why doesn't this string format as currency?
It looks like (based on the variable name strOrderTotal ) that your total is already a string. The "C" format specifier converts a...
Read more >
Standard numeric format strings
In this article, learn to use standard numeric format strings to format common ... More information: The Currency ("C") Format Specifier.
Read more >
String.Format Method (System)
Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to...
Read more >
What is a concise function that formats a (String) decimal ...
The formatting now includes the correct currency symbol for the user's locale (and currency formatting should it differ from standard decimal ...
Read more >
Currency formatting... again
The problem when using the outputText formatting is that numbers won't change from xxx,xxx,xxx.00 to xxx.xxx.xxx,00, I mean change point decimal ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found