StructureJS
0.15.2A class based utility library for building modular and scalable web platform applications. Features opt-in classes and utilities which provide a solid foundation and toolset to build your next project.
The NumberUtil class has many helper methods to work with number data.
bytesToMegabytes
bytes
celsiusToFahrenheit
celsius
decimals
centimeterToInch
cm
convertToHHMMSS
seconds
showHours
Converts seconds into hour, minutes, seconds.
NumberUtil.convertToHHMMSS(33333);
// '09:15:33'
doubleDigitFormat
num
fahrenheitToCelsius
fahrenheit
decimals
feetToMeter
feet
formatUnit
value
[decimalPlacement=2]
[decimalSeparator='.']
[thousandsSeparator=',']
[currencySymbol='']
[currencySymbolPlacement=0]
Formats a number as a currency string.
value
Number
The number value you want formatted.
[decimalPlacement=2]
Number
optional
How many decimal placements you want to show.
[decimalSeparator='.']
String
optional
The character you want to use as the thousands separator.
[thousandsSeparator=',']
String
optional
The character you want to use as the thousands separator.
[currencySymbol='']
String
optional
The symbol you would like to add.
[currencySymbolPlacement=0]
Number
optional
The placement of the symbol. Use 0 to place in front or 1 to place at the end.
Returns the formatted currency.
NumberUtil.formatUnit(1234567.89, 2, ".", ",", "$", 0);
// '$1,234,567.89'
NumberUtil.formatUnit(12341234.56, 2, "*", ",", " €", 1);
// '12,341,234*56 €'
NumberUtil.formatUnit(-1900.24, 1);
// '-1,900.2'
inchToCentimeter
inch
unformatUnit
value
Formats a currency string as a number.
value
String
The string currency that you want converted into a number.
Returns the number value of the currency string.
NumberUtil.unformatUnit('$1,234,567.89');
// 1234567.89
NumberUtil.unformatUnit('1.234.567,89 €');
// 1234567.89
NumberUtil.unformatUnit('$-123,456,789.99');
// -123456789.99