I have a WPF screen and a TextBox field which should display a calculated percentage value (which is a double). The value is already correct i.e. it is 21 for 21% (therefore does not need to be multiplied by 100) but it has decimal places and I need to add the % symbol.
I do not wish to round in the C# code as I lose my precision which is required in other calculations. I simply wish to use StringFormat in the XAML to put a format mask on the number. So 21.333 should be seen on screen as 21%.
This is what works so far to truncate off the decimal places but no matter the configuration I try I cannot seem to add the % symbol as well.
Text="{Binding Brokerage, StringFormat='0,0.'}"
Your help is appreciated.
Use the fixed-point numeric format string with zero decimal places, F0
:
<TextBlock Text="{Binding Brokerage, StringFormat={}{0:F0}%}"/>
{Binding OrderQTY, StringFormat={0:0.##}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With