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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@DannyLee89 @miloush, as per my understanding we have reached to a conclusion on this issue, right ?? Is it alright to close this ?
Closing this issue