toFixedLength
toFixedLength(
value,length,options?):string
Defined in: packages/core/src/number/to-fixed-length.ts:54
Format a number to a fixed length string, with options for maximum fraction digits, fixed fraction digits, and rounding method. If the number exceeds the maximum value that can be represented with the given length and fraction digits, it will be clamped to that maximum value.
Examples with fixedLength=5, fractionDigits=2, fixedFractionDigits=true : 0.012 => 00.01 (rounded) 0.123 => 00.12 (rounded) 1.234 => 01.23 (rounded) 12.345 => 12.35 (rounded) 123.456 => 99.99 (max) .. 123456.789 => 99.99 (max)
Examples with fixedLength=5, fractionDigits=2, fixedFractionDigits=false : 0.012 => 00.01 (rounded) 0.123 => 00.12 (rounded) 1.234 => 01.23 (rounded) 12.345 => 12.35 (rounded) 123.456 => 123.5 (rounded) 1234.567 => 999.9 (max) 12345.678 => 12346 (rounded) 123456.789 => 99999 (max)
Examples with fixedLength=5, fractionDigits=3, fixedFractionDigits=false : 0.012 => 0.012 0.123 => 0.123 1.234 => 1.234 12.345 => 12.35 (rounded) 123.456 => 123.5 (rounded) 1234.567 => 999.9 (max) 12345.678 => 12346 (rounded) 123456.789 => 99999 (max)
Examples with fixedLength=6, fractionDigits=2, fixedFractionDigits=false : 0.012 => 000.01 (rounded) 0.123 => 000.12 (rounded) 1.234 => 001.23 (rounded) 12.345 => 012.35 (rounded) 123.456 => 123.46 (rounded) 1234.567 => 1234.6 (rounded) 12345.678 => 9999.9 (max) 123456.789 => 123457 (rounded) 1234567.891 => 999999 (max)
Parameters
Section titled “Parameters”number
The number to format.
length
Section titled “length”number
The fixed length of the output string (including decimal point if any).
options?
Section titled “options?”Options for formatting.
Returns
Section titled “Returns”string
The formatted number as a string.