ToText method (number)

Returns this number as a text representation, using the specified format.

Syntax

number.ToText
number.ToText(format)

Returns the text representation of number as specified by format.

format: A standard or custom number format.

The default value for format is 'G'.

Standard number formats

Format specifier Name Description Examples
'C' or 'c' Currency A currency value.
A number suffix can be used to force a decimal precision.
1.4567 ('C') -> £1.46
7 ('C') -> £7.00
4.5678 ('C3') -> £4.568
'E' or 'e' Exponential (scientific) Exponential notation.
A number suffix can be used to force a decimal precision.
1234.56 ('E') -> 1.23456E+003
1234.56 ('e2') -> 1.23e+003
'F' or 'f' Fixed point Converts the number to a text "-ddd.ddd…" notation.
A number suffix can be used to force a decimal precision, otherwise the default precision for the culture is used.
1234.5678 ('F') -> 1234.57
1234 ('F2') -> 1234.00
'G' or 'g' General Converts the number to a text "-ddd.ddd…" notation.
A number suffix can be used to force a decimal precision, otherwise the full precision is used.
1234.5678 ('G') -> 1234.5678
1234.5678 ('G2') -> 1234.57
'N' or 'n' Number Integral and decimal digits, group separators, and a decimal separator with optional negative sign.
A number suffix can be used to force a decimal precision, otherwise the default precision for the culture is used.
1234.5678 ('N') -> 1,234.57
1234.5678 ('N3') -> 1,234.568
'P' or 'p' Percent Number multiplied by 100 and displayed with a percent symbol.
A number suffix can be used to force a decimal precision, otherwise the default precision for the culture is used.
1 ('P') -> 100.00%
0.512 ('P') -> 51.20%
0.5 ('P0') -> 50%
Any other single character Unknown Causes a template error.  

Custom number formats

Format specifier Name Description Examples
'0' Zero place-holder Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result. 1234.5678 ('00000') -> 01235
0.4567 ('0.00') -> 0.46
'#' Digit place-holder Replaces the "#" symbol with the corresponding digit if one is present; otherwise, no digit appears in the result. 1234.5678 ('#####') -> 1235
0.4567 ('#.##') -> .46
'.' Decimal point Determines the location of the decimal separator in the result. 0.4567 ('0.00') -> 0.46
',' Group separator and number scaling Serves as both a group separator and a number scaling specifier.
As a group separator, it inserts a localised group separator character between each group.
As a number scaling specifier, it divides a number by 1000 for each comma specified.
Group separator specifier:
2147483647 ('##,#') -> 2,147,483,647
 
Scaling specifier:
2147483647 ('#,#,,') -> 2,147
'%' Percentage place-holder Multiplies a number by 100 and inserts a localized percentage symbol in the result. 0.3697 ('%#0.00') -> %36.97
0.3697 ('##.0 %') -> 37.0 %
'‰' Per mille place-holder Multiplies a number by 1000 and inserts a localized per mille symbol in the result. 0.03697 ('#0.00‰') -> 36.97‰
'E0'
'E+0'
'E-0'
'e0'
'e+0'
'e-0'
Exponential notation If followed by at least one 0 (zero), formats the result using exponential notation.
The case of "E" or "e" indicates the case of the exponent symbol in the result.
The number of zeros following the "E" or "e" character determines the minimum number of digits in the exponent.
A plus sign (+) indicates that a sign character always precedes the exponent whereas a minus sign (-) indicates that a sign character precedes only negative exponents.
987654 ('#0.0e0') -> 98.8e4
1503.92311 ('0.0##e+00') -> 1.504e+03
1.8901385E-16 ('0.0e+00') -> 1.9e-16
\ Escape character Causes the next character to be interpreted as a literal rather than as a custom format specifier. 987654 ('\###00\#') -> #987654#
'text'
"text"
Literal text delimiter Indicates that the enclosed characters should be copied to the result unchanged. 68 ('# " degrees"') -> 68 degrees
68 ('#" degrees"') -> 68 degrees
; Section separator Defines sections with separate format strings for positive, negative, and zero numbers. 12.345 ('#0.0#;(#0.0#);-\0-') -> 12.35
0 ('#0.0#;(#0.0#);-\0-') -> -0-
-12.345 ('#0.0#;(#0.0#);-\0-') -> (12.35)
12.345 ('#0.0#;(#0.0#)') -> 12.35
0 ('#0.0#;(#0.0#)') -> 0.0
-12.345 ('#0.0#;(#0.0#)') -> (12.35)
Other All other characters The character is copied to the result string unchanged. 68 ('# aaa') -> 68 aaa

Examples

{% Var number1 = 1234.5678 %}
{% Var number2 = 0.1234 %}

Answers: {{ number1.ToText('0.00') }},
         {{ number1.ToText('##,#') }}.
         {{ number2.ToText('#%') }}.

The above example would output: Answers: 1234.56, 1,234, 12% (for the 'en-GB' culture).