Top  | Previous | Next

Strings / numberFormat

numberFormat(number, pattern)

Returns a string version of the number argument, formatted as specified by the pattern string. This is commonly used to specify the number of decimal places to display, but can be used for more advanced formatting as well. The pattern string is a numeric format string, which may include any of these characters that instruct it how to format the number.

 

0

Specifies a required digit

E

Scientific notation

#

Specifies an optional digit

;

Used to separate positive and negative patterns

,

The grouping separator

%

Multiplies the value by 100 and shows as a percent

-

A minus sign

'

Used to quote special characters

 

This table shows some numbers, and the result of using various format strings to format them.

 

Number

Pattern

Result

5

0

5

5

0.0

5.0

5

00.0

05.0

123

#,##0

123

1024

#,##0

1,024

1337

#,##0.#

1,337

1337.57

#,##0.#

1,337.6

87.32

#,##0.0000

87.3200

-1234

#,##0

-1,234

-1234

#,##0;(#,##0)

(1,234)

4096

0.###E0

4.096E3

.348

#.00%

34.80%

34.8

#0.00'%'

34.80%

 

Example:

numberFormat(34.8, "#0.00'%'")

... returns the string "34.80%"