New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Formatting Numeric Values

The NumberFormat property controls how RadNumericTextBox formats its value. The format that you specify in this way is applied when the numeric text box does not have focus. During editing, RadNumericTextBox always uses the actual number.

The value of NumberFormat takes precedence over both the Type property and the Culture property.

NumberFormat is a composite property with the following sub-properties:

 

Sub-propertyTypeDescription
AllowRoundingBooleanSpecifies whether the value is rounded ( when set to true ) or truncated ( when set to false ) when the number of decimal places exceeds the value of DecimalDigits.
KeepNotRoundedValueBooleanSpecifies whether the control will keep its not rounded value ( when set to true ) and show it when it is focused. Otherwise ( when set to false ) the old behavior is preserved, where the actual value of the control is the rounded value. By default this property is set to false .
KeepTrailingZerosOnFocusBooleanSpecifies whether the control will keep its zero numbers( when set to true ) and show them when it is focused, according to the DecimalDigits setting. Otherwise ( when set to false ) the old behavior is preserved - the control will not display decimal zeros when focused. By default this property is set to false .
DecimalDigitsIntegerSpecifies the number of digits that are displayed after the decimal separator.
DecimalSeparatorCharacterSpecifies the character that separates the fractional portion of a number.
GroupSeparatorCharacterSpecifies the character that separates each group of digits.
GroupSizesIntegerSpecifies the number of digits in each group, starting from the decimal separator.
NegativePatternStringSpecifies the pattern for formatting negative values. (See below for details on formatting patterns.)
PositivePatternStringSpecifies the pattern for formatting positive values. (See below for details on formatting patterns.)
ZeroPatternStringSpecifies the pattern for formatting the value when it equals zero. (See below for details on formatting patterns.)

AllowRounding property is also responsible for displaying trailing zeros in the number. When set to true, trailing zeros will be added to fulfill the number of decimal places specified in the DecimalDigits property (e.g. 8.5 displayed as 8.50). When set to false, and the value is not occupying the allowed digits, no additional zeros will be added at the end of the number.

Formatting patterns

Formatting patterns are strings that control the placement of elements when formatting a numeric value. A Formatting pattern consists of the special symbol n, which represents the number, plus any literal characters that are part of the formatted value. Typically, the literal values are characters such as the negative sign ("-"), a currency symbol ("$"), parentheses, and so on.

The characters other than n in a formatting pattern are literal symbols. If you use the dollar sign ("$") as a currency symbol, for example, currency values are formatted using that symbol regardless of the value of the Culture property.

The NumberFormat inner tag of the RadNumericBox exposes three different patterns that can be specified: PositivePatten, NegativePattern, and ZeroPattern. Sample usage is demonstrated below:

ASPX
<telerik:RadNumericTextBox runat="server" ID="RadNumericTextBox1" Value="2" ShowSpinButtons="true" Width="100" Skin="Material">
    <NumberFormat AllowRounding="false" DecimalDigits="0"
        PositivePattern="+n°C"
        NegativePattern="-n°C"
        ZeroPattern="±n°C" />
</telerik:RadNumericTextBox>

Formatting patterns sample

For a live example of different NumberFormat settings, see Formatting Value.

Numeric value precision

Since the RadNumericTextBox operates on both client and server side, it is limited by the data types used in C# and JavaScript. Although it could be bound to Decimal type using its DbValue property, its precision will be limited to JavaScript’s Number type. Therefore, it is recommended to use only numbers within the range of Double type, which means that you will get only 15-16 digit precision.

Number Separators

GroupSeparator and DecimalSeparator should not be set as the same character. By default they are culture depended meaning that in “en-US” culture the default group separator would be ‘,’ (comma) and the default decimal separator would be ‘.’ (dot). If you decide to change one of the separators to the character which is already assigned to the other separator, you should also modify the character for the latter separator.

See Also