FormatNumber
This function formats a string as a number.
Format patterns follow the C# format types outlined in the official Microsoft documentation:
Some of these custom formats are supported:
Arguments
FormatNumber(1,2,3)
Ordinal | Type | Required | Description |
---|---|---|---|
1 | String | True | The number string to format |
2 | String | True | The output format pattern (see table below for values) |
3 | String | False | ISO code for locale-specific pattern elements |
NOTE: By default, this function rounds half up to two decimal places.
Here are a few examples of format patterns, given a number of 123
:
Element | Format Pattern | Output |
---|---|---|
Currency | C or c |
$123.00 |
Decimal | D or d |
123 |
Exponential (scientific) | E or e |
1.230000E+002 |
Fixed-point | F of f |
123.00 |
General | G or g |
123 |
Number | N or n |
123.00 |
Percent | P or p |
12,300.00 % |
Hexadecimal | X or x |
7B |
NOTE: The D
pattern requires an integer for input.
Here are a few examples of custom format patterns, given a number of -1.8967
:
Element | Format Pattern | Example | Output |
---|---|---|---|
Zero placeholder | 0 |
"0000" |
-0002 |
Digit placeholder | # |
"###0" |
-2 |
Decimal point | . |
"#0.00" |
-1.90 |
Group separator and scaling | , |
"0,00#.##" |
-0,001.9 |
Percentage placeholder | % |
"#.00%" |
-189.67% |
Exponential notation | E0 , E+0 , e0 or e+0 |
"#0.0e0" |
-19.0e-1 |
Escape character | \ |
"\###0.000\#" |
-#1.897# |
Literal string delimiter | 'string' or "string" |
"#.##' points'" |
-1.9 points |
Section separator | ; |
"#0.00;(#0.00)" |
(1.90) |
Example 1
Output
Example 2
Not a subscriber? Subscribe now.
Example 3
Not a subscriber? Subscribe now.