Number Formatting in SfNumericTextBox

13 Oct 20223 minutes to read

The values of the SfNumericTextBox can be configured to display different formats like currency format, percent format etc.

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ā€.

Display Currency Notation

c - Displays the value with currency notation.

  • C#
  • [C#]
    	
    numericTextBox.FormatString = "c";

    Display Number Notation

    n ā€“ Display the value in number format.

  • C#
  • [C#]
    	
    numericTextBox.FormatString = "n";

    Display Percentage Notation

    p ā€“ Display the value in percentage.

  • C#
  • [C#]
    
    numericTextBox.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 SfNumericTextBox.

    Display the SfNumericTextBox with FormatString

    Parser Input Value

    The value of the SfNumericTextBox can be parsed based on the ParserMode property.

    NOTE

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

  • C#
  • [C#]
    
    numericTextBox.ParserMode = SFNumericTextBoxParsers.Decimal;

    Display the SfNumericTextBox with ParserMode

    Compute to Percentage

    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#]
        
      numericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Value;
    • Compute: Displays the computed value with percentage symbol.

    • C#
    • [C#]
        
      numericTextBox.PercentDisplayMode = SFNumerictextBoxPercentDisplayMode.Compute;

    Display the SfNumericTextBox with PercentDisplayMode

    Group separator modes

    GroupSeparatorMode provides 2 states to display the group separator.
    When the mode is set as Always, it will display separator while typing itself on the other hand when the mode is set as LostFocus it will enable the separator when the control lost its focus.

    NOTE

    EnableGroupSeparator property must be enabled to use the GroupSeparatorMode.

    SfNumericTextBox numericTextBox = new SfNumericTextBox();
                numericTextBox.Frame = this.View.Frame;
                numericTextBox.Value = 123456;
                numericTextBox.FormatString = "n";
                numericTextBox.GroupSeparatorMode = GroupSeparatorMode.Always;
                numericTextBox.EnableGroupSeparator = true;
                this.Add(numericTextBox);

    Display the value with enable group separator