View source

class thx.format.NumberFormat

Available on all platforms

Class Fields

static function binary(f:Float, significantDigits:Int = 1, ?culture:Culture):String

Binary format. The result is prefixed with leading 0 up to significantDigits. Default is one.

static function currency(f:Float, ?precision:Int, ?symbol:String, ?culture:Culture):String

Formats a currency value. By default the currency symbol is extracted from the applied culture but it can be optionally provided using setting the symbol argument.

static function customFormat(f:Float, pattern:String, ?culture:Culture):String

Custom format uses a pattern composed of the format options described below.

0Zero placeholder is replaced with a corresponding digits if present, otherwise a 0 is printed.
#Digit placeholder is replaced with a corresponding digits if present or nothing.
.Localized decimal separator.
,Localized group separator. If added to the end of the pattern it multiplies the number by 1000 for every comma.
%Includes the percentage symbol and multiplies the number by 100.
Includes the permille symbol and multiplies the number by 1000.
E0, E+0, E-0, e0, e+0, e-0Exponential notation.
\Escapes the following character.
'...', "..."Escape an entire sequence of characters.
;Section separator. There are three possible sections (positive, negative, zero). If two are specified zero numbers use the format from the first section.
...Anything else is left untouched and put in the output as it is.

static function decimal(f:Float, significantDigits:Int = 1, ?culture:Culture):String

Formats a decimal (integer) value.

static function exponential(f:Float, precision:Int = 6, digits:Int = 3, symbol:String = "e", ?culture:Culture):String

Formats a number using the exponential (scientific) format.

static function fixed(f:Float, ?precision:Int, ?culture:Culture):String

Formats a fixed point float number with an assigned precision.

static function format(f:Float, pattern:String, ?culture:Culture):String

Formats a number using the specified pattern.

A printf format is formatted using the rules described for NumberFormat.printf.

A multi character format uses the formatting rules described for NumberFormat.customFormat.

A single character format adopts the following options:

C or cCurrency format.
D or dDecimal format.
eExponential (scientific) format.
ELike e but with capitalized E symbol
F or fFixed decimal format (no thousand separators).
gGeneral format (shortest between e and f).
GLike g but if format is exponential uses the upper case E symbol
N or nNumber format (uses thousand separators if required).
P or pPercent format.
R or rRoundtrip format.
xHexadecimal format.
XSame as x but prefixed with 0X.
%...Delegates to printf
...Delegates to customFormat

static function general(f:Float, ?significantDigits:Int, ?culture:Culture):String

Formats a number using either the shortest result between fixed and exponential.

static function hex(f:Float, significantDigits:Int = 1, ?culture:Culture):String

Formats a number to hexadecimal format.

static function integer(f:Float, ?culture:Culture):String

Formats the integer part of a number.

static function number(f:Float, ?precision:Int, ?culture:Culture):String

Formats a number with group separators (eg: thousands separators).

static function octal(f:Float, significantDigits:Int = 1, ?culture:Culture):String

Formats a number to octals.

static function percent(f:Float, ?decimals:Int, ?culture:Culture):String

Formats a number as a percent value. The output result is multiplied by 100. So 0.1 will result in 10%.

static function permille(f:Float, ?decimals:Int, ?culture:Culture):String

Formats a number as a percent value. The output result is multiplied by 1000. So 0.1 will result in 100‰.

static function printf(f:Float, pattern:String, ?culture:Culture):String

Formats a single number in a String using the printf conventions.

The printf format uses the following pattern:

ban unsigned integer, in binary
Blike %b, but using an upper-case "B" with the # flag
dSigned decimal integer
eScientific notation (mantissa/exponent) using e character
ELike %e, but using an upper-case "E"
fDecimal floating point
gUse the shorter of %e or %f.
GLike %g, but with an upper-case "E" (if applicable)
iSame as d
oSigned octal
uUnsigned decimal integer
xUnsigned hexadecimal integer
XLike %x, but using upper-case letters
%% Character

-Left-justify within the given field width; Right justification is the default (see width sub-specifier).
+Forces to preceed the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a - sign..
(space)If no sign is going to be written, a blank space is inserted before the value.
#Used with o, x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values different than zero. If b or B prefixes the output with either.
0Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier).
(number)Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
.numberFor integer specifiers (d, i, o, u, x, X): precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0. For e, E and f specifiers: this is the number of digits to be printed after de decimal point. For g and G specifiers: This is the maximum number of significant digits to be printed. By default all characters are printed until the ending null character is encountered. For c type: it has no effect. When no precision is specified, the default is 1. If the period is specified without an explicit value for precision, 0 is assumed.

Differences with classic printf:

length parameter is not supported to set the type of the integer argument (eg. short or unsigned) * width is not supported .* precision is not supported %p pointer address is not supported %n is not supported %s is not supported since this function is to format numeric values only

static function toBase(value:Int, base:Int, ?culture:Culture):String

Transform an Int value to a String using the specified base. A negative sign can be provided optionally.

static function unit(f:Float, decimals:Int, unitSymbol:String, ?culture:Culture):String

Formats a number with a specified unitSymbol and a specified number of decimals.

Toggle inherited fields