Number Formatting
The purpose of number formatting is to convert a Number
object to a human readable string using the culture-specific settings.
The kendo.format
and kendo.toString
methods support standard and custom numeric formats.
Default Number Formats
-
"n"
—Renders a number.kendo.culture("en-US"); kendo.toString(1234.567, "n"); //1,234.57
kendo.toString(10.12, "n5"); //10.12000 kendo.toString(10.12, "n0"); //10
kendo.culture("de-DE"); kendo.toString(1234.567, "n3"); //1.234,567
-
"c"
—Renders a currency value.kendo.culture("en-US"); kendo.toString(1234.567, "c"); //$1,234.57
kendo.culture("en-US"); kendo.toString(1234.567, "c0"); //$1,235
kendo.culture("de-DE"); kendo.toString(1234.567, "c3"); //1.234,567 €
-
"p"
—Renders a percentage (number is multiplied by 100).kendo.culture("en-US"); kendo.toString(0.222, "p"); //22.20 %
kendo.culture("en-US"); kendo.toString(0.222, "p0"); //22 %
kendo.culture("de-DE"); kendo.toString(0.22, "p3"); //22.000 %
-
"e"
—Renders exponential values.kendo.toString(0.122, "e"); //1.22e-1 kendo.toString(0.122, "e4"); //1.2200e-1
Custom Number Formats
You can also create a custom numeric format string by using one or more custom numeric specifiers. A custom numeric format string is any string which is not a standard numeric format.
The following specifiers are supported by Kendo UI:
-
"0"
—The zero placeholder replaces the zero with the corresponding digit if such is present. Otherwise, zero appears in the result string.kendo.toString(1234.5678, "00000") -> 01235
-
"#"
—The digit placeholder replaces the pound sign with the corresponding digit if one is present. Otherwise, no digit appears in the result string. Cannot be used to format a number as a telephone number, that is,(###)-###-####
.kendo.toString(1234.5678, "#####") -> 1235
-
"."
—The decimal placeholder determines the location of the decimal separator in the result string.kendo.toString(0.45678, "0.00") -> 0.46 (en-US)
-
","
—The group separator placeholder inserts a localized group separator between each group.kendo.toString(12345678, "##,#") -> 12,345,678(en-US)
"%"
—The percentage placeholder multiplies a number by 100 and inserts a localized percentage symbol in the result string. The%
symbol is interpreted as a format specifier in the format string. To prevent this behavior, precede the%
symbol with a double backslash -kendo.toString(12, "# \\\%")
-> 12 % (en-US)."$"
—The currency placeholder specifies that the number will be formatted by using the currency culture settings. The$
symbol is replaced with the localized currency symbol.$
is interpreted as a format specifier in the format string. To prevent this behavior, precede the$
symbol with a double backslash -kendo.toString(12, "# \\\$")
-> 12 $ (en-US).-
"e"
—The exponential notation.kendo.toString(0.45678, "e0") -> 5e-1
";"
—The section separator defines sections with separate format strings for positive, negative, and zero numbers.-
"string"/'string'
—The literal string delimiter indicates that the enclosed characters will be copied to the result string.