Number Formatting in NumericUpDown

29 Jun 2020 / 1 minute to read

Format String

The FormatString property determines the format specifier by which the display text has to be formatted.

NOTE

The control displays the formatted text on lost focus. Default Value of FormatString is ā€œnā€.

It has three types,

  • c - Display the value with currency notation.
  • c#
  • [C#]
    	
    numeric.FormatString = "c";
    • n ā€“ Display the value in number format.
  • c#
  • [C#]
    	
    numeric.FormatString = "n";
    • p ā€“ Display the value in Percentage.
  • c#
  • [C#]
    
    numeric.FormatString = "p";

    NOTE

    Instead of using above FormatString types, we can provide any symbol or value as string in FormatString property which will be appended with the value in NumericUpDown.

    Display the NumericUpDown with number formating

    Parser Mode

    The value of the NumericUpDown can be parsed based on the ParsingMode property.

    NOTE

    The ParsingMode is of type Parsers containing enum values of Double and Decimal. The default Value for ParsingMode is Double.

  • c#
  • [C#]
    
    numeric.ParsingMode = SFNumericUpDownParsingMode.Decimal;

    Display the NumericUpDown with parser mode

    Percent Display Mode

    The PercentDisplayMode property can be used to display numeric data in Percent mode.

    NOTE

    The control displays the percent value on lost focus.

    It provides the following options:

    • Value: Displays the value with percentage symbol.
  • c#
  • [C#]
    
    numeric.PercentDisplayMode = SFNumericUpDownPercentDisplayMode.Value;
    • Compute: Displays the computed value with percentage symbol.
  • c#
  • [C#]
    
    numeric.PercentDisplayMode = SFNumericUpDownPercentDisplayMode.Compute;

    Display the NumericUpDown with percent mode