Telerik UI for Windows 8 HTML

Telerik controls that offer date and numeric formatting use common format strings. This article will introduce you to the formatting options available.

The format string is specified using the following pattern:

 Copy imageCopy
"{0:formatPlaceholders}"

The format placeholders are listed in the following sections.

Formatting Numbers

Standard Numeric Formats

  • "n" for number

    A number like 1234.567 will be displayed like 1,234.57 with format "n"(thousands separator and two digits after the decimal point).

    A number like 1234.567 will be displayed like 1,235.567 with format "n3" (thousands separator and three digits after the decimal point).

  • "c" for currency

    A number like 1234.567 will be displayed like $1,234.57 with format "c" (currency sign, thousands separator, and two digits after the decimal point).

    A number like 1234.567 will be displayed like $1,235 with format "c0" (currency sign, thousands separator, and no digits after the decimal point).

  • "p" for percentage (number is multiplied by 100)

    A number like 0.222 will be displayed like 22.20 % with format "p" (percent sign and two digits after the decimal point).

    A number like 0.222 will be displayed like 22 % with format "p0" (percent sign and no digits after the decimal point).

  • "e" for exponential

    A number like 0.122 will be displayed like 1.22e-1 with format "e" (two digits after the decimal point and exponent).

    A number like 0.122 will be displayed like 1.2200e-1 with format "e4" (four digits after the decimal point and exponent).

Custom Numeric Formats

You can create custom numeric format string using one or more custom numeric placeholders. Custom numeric format string is any that is not a standard numeric format. Here is a list of the supported format placeholders:

  • "0" - zero placeholder

    Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string - 1234.5678 formatted with "00000" will look like 01235.

  • "#" - digit placeholder

    Replaces the pound sign with the corresponding digit if one is present; otherwise, no digit appears in the result string - 1234.5678 formatted with "#####" will look like 1235.

    Note: The "#" placeholder cannot be used to format a number as a telephone number, i.e. (###)-###-####

  • "." - decimal placeholder

    Determines the location of the decimal separator in the result string - 0.45678 formatted with "0.00" becomes 0.46.

  • "," - group separator placeholder

    Insert a localized group separator between each group - 12345678 formatted with "##,#" becomes 12,345,678.

  • "%" - percentage placeholder

    Multiplies a number by 100 and inserts a localized percentage symbol in the result string.

  • ";" - section separator

    Defines sections with separate format strings for positive, negative, and zero numbers.

  • "string"/'string' - literal string delimiter

    Indicates that the enclosed characters should be copied to the result string.

Formatting Dates

Standard Date Formats

For the examples in the following list, we will use the date Sat Nov 06 2010.

  • "d" - short date pattern

    The date will be formatted as: 11/6/2010.

  • "D" - long date pattern

    The date will be formatted as: Monday, November 06, 2010.

  • "F" - full date/time pattern (number is multiplied by 100)

    The date will be formatted as: Monday, November 06, 2010 12:00:00 AM.

  • "g" - general date/time pattern (short time)

    The date will be formatted as: 11/6/2010 12:00 AM.

  • "G" - general date/time pattern (long time)

    The date will be formatted as: 11/6/2010 12:00:00 AM.

  • "m|M" - month/day pattern

    With format "{0:m}" the date will be formatted as: November 06.

  • "u" - universal sortable date/time pattern

    The date will be formatted as: 2010-11-06 00:00:00Z.

  • "y|Y" - month/year pattern

    With format "{0:y}" the date will be formatted as: November, 2010.

Custom Date Formats

You can create custom date formats by using one or more custom date placeholders. A custom date format string is any that is not a standard date format. Here is a list of the supported format placeholder:

For the examples in the following list, we will use the date Tue Jul 06 2010.

  • "d" - the day of the month, from 1 to 31

  • "dd" - the zero-padded day of the month - from 01 to 31

  • "ddd" - the abbreviated name of the day of the week

    With format "{0:ddd, d MMM, yyyy}" the date will be formatted as: Tue, 6 Jul, 2010 .

  • "dddd" - the full name of the day of the week

    With format "{0:dddd, d MMM, yyyy}" the date will be formatted as: Tuesday, 6 Jul, 2010 .

  • "M" - the month, from 1 to 12

  • "MM" - the zero-padded month, from 01 to 12

  • "MMM" - the abbreviated name of the month

    With format "{0:ddd, d MMM, yyyy}" the date will be formatted as: Tue, 6 Jul, 2010 .

  • "MMMM" - the full name of the month

    With format "{0:dddd, d MMMM, yyyy}" the date will be formatted as: Tuesday, 6 July, 2010 .

  • "yy" - the year, from 00 to 99

    With format "{0:dddd, d MMMM, yy}" the date will be formatted as: Tuesday, 6 July, 10.

  • "yyyy" - the year as a four-digit number

    With format "{0:dddd, d MMMM, yyyy}" the date will be formatted as: Tuesday, 6 July, 2010.

  • "h" - the hour, using 12-hour clock - from 1 to 12

  • "hh" - the zero-padded hour, using 12-hour clock - from 01 to 12

  • "H" - the hour, using 24-hour clock - from 0 to 23

  • "HH" - the zero-padded hour, using 24-hour clock - from 00 to 23

  • "m" - the minute, from 0 to 59

  • "mm" - the zero-padded minute, from 00 to 59

  • "s" - the second, from 0 to 59

  • "ss" - the zero-padded second, from 00 to 59

  • "f" - the tenths of a second

  • "ff" - the hundreds of a second

  • "fff" - the milliseconds

  • "tt" - the AM/PM designator

See Also