Numeric Formatting with non-period Decimal Point separator

Posted by: msloan on 27 October 2020, 10:56 pm EST

    • Post Options:
    • Link

    Posted 27 October 2020, 10:56 pm EST

    Hi,

    I am finding the floating point numbers formatted with N or F into string are appearing with PERIOD decimal points even though the system’s decimal point separator is set to a COMMA. I have found this the case with Text Boxes and the Data Grid. What am I missing?

    Mark Sloan

  • Posted 28 October 2020, 6:41 pm EST

    Hi Mark,

    This behavior is by design in WPF as Binding doesn’t respect the CurrentCulture by default i.e it uses the neutral culture settings. Therefore, In order to make it use the current culture we have to set the Binding’s ConverterCulture property as follows:

    
    <c1:DataGridNumericColumn Binding="{Binding Sale, ConverterCulture={x:Static glob:CultureInfo.CurrentCulture}}" Format="F" Header="Sale"></c1:DataGridNumericColumn>
    
    

    Just in case needed you can also create a CustomBinding class so that you don’t have to set ConverterCulture everywhere as follows:

    
    // C#
    public class CustomBinding : Binding
    {
          public CustomBinding(string path) : base(path)
          {
               ConverterCulture = CultureInfo.CurrentCulture;
          }
    }
    
    // XAML
     <TextBox x:Name="txt" Margin="5" Width="100" Text="{local:CustomBinding Value}" HorizontalAlignment="Left"></TextBox>
    
    

    Please refer the same from the attached sample. (see NumericFormat.zip)

    Regards,

    Kartik

    NumericFormat.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels