StructureJS
0.14.6A 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
Converts bytes into megabytes.
bytes
Number
celsiusToFahrenheit
celsius
decimals
Convert Celsius to Fahrenheit.
celsius
Number
The celsius value.
decimals
Number
The number of decimals.
MathUtil.celsiusToFahrenheit(0);
// 32
MathUtil.celsiusToFahrenheit(100);
// 212
centimeterToInch
cm
Converts centimeters into inches.
cm
Number
NumberUtil.centimeterToInch(1);
// 0.3937
convertToHHMMSS
seconds
showHours
Converts seconds into hour, minutes, seconds.
seconds
Number
showHours
Object
[boolean=true] By default if the time does not pass one hour it will show 00:05:34. Pass false to display the time as 05:34 until it gets pass one hour and then it will show 01:00:00
NumberUtil.convertToHHMMSS(33333);
// '09:15:33'
doubleDigitFormat
num
Formats a number from 0-9 to display with 2 digits.
num
Number
NumberUtil.doubleDigitFormat(0);
// '00'
NumberUtil.doubleDigitFormat(5);
// '05'
NumberUtil.doubleDigitFormat(9);
// '09'
fahrenheitToCelsius
fahrenheit
decimals
Convert Fahrenheit to Celsius.
fahrenheit
Number
The fahrenheit value.
decimals
Number
The number of decimals.
MathUtil.fahrenheitToCelsius(32);
// 0
MathUtil.fahrenheitToCelsius(212);
// 100
feetToMeter
feet
Converts feet into meters.
feet
Number
NumberUtil.feetToMeter(1);
// 0.3048
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
Converts inches into centimeters.
inch
Number
NumberUtil.inchToCentimeter(1);
// 2.54
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