numberFormatUtil
A simple utility for formatting numbers in human readable format.
Functions
numberToTuple
numberFormatUtil.
numberToTuple
(
number:
number
) →
string?
Returns the given number
's tuple, if any. Supports up to 57
tuples!
print(numberFormatUtil.numberToTuple(2)) --> "Double"
print(numberFormatUtil.numberToTuple(3)) --> "Triple"
print(numberFormatUtil.numberToTuple(4)) --> "Quadruple"
ordinal
numberFormatUtil.
ordinal
(
number:
number
) →
string
Returns the given number in ordinal format.
print(numberFormatUtil.ordinal(24)) --> "24th"
spsToMph
numberFormatUtil.
spsToMph
(
sps:
number
) →
number
Formats sps
(studs per second) to mph
(miles per second).
print(numberFormatUtil.spsToMph(100, 50, 25)) --> 0.75
suffix
numberFormatUtil.
suffix
(
number:
number
) →
string
Return a string as the formatted version of number
.
Cannot format extremely large numbers
This method will struggle to format numbers larger than approximately 10^68
.
print(numberFormatUtil.suffix(10^70)) --> 10 (no formatting...)
print(numberFormatUtil.suffix(1650)) --> "1.65K"
Additionally, if number
is lower than 1
, then this method will just return number
(stringified).
commas
numberFormatUtil.
commas
(
target:
number
) →
string
Returns a number stringified, formatted with commas.
print(numberFormatUtil.commas(15000)) --> 15,000
toHMS
numberFormatUtil.
toHMS
(
seconds:
number
) →
string
Returns the given seconds
formatted in HMS
format as a string.
print(numberFormatUtil.toHMS(3600)) --> "01:00:00"
toMS
numberFormatUtil.
toMS
(
seconds:
number
) →
string
Returns the given seconds
formatted in MS
format as a string.
print(numberFormatUtil.toHMS(60)) --> "01:00"
toS
numberFormatUtil.
toS
(
seconds:
number
) →
string
Returns the given seconds
formatted in S
format as a string.
print(numberFormatUtil.toHMS(60)) --> "1:00"