StructureJS

0.15.2

A 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.

NumberUtil Class

Module: util
Parent Module: StructureJS

The NumberUtil class has many helper methods to work with number data.

Index

Show:

Methods

bytesToMegabytes
(
  • bytes
)
Number public static

Converts bytes into megabytes.

Parameters:

Returns:

Example:

celsiusToFahrenheit
(
  • celsius
  • decimals
)
Number

Convert Celsius to Fahrenheit.

Parameters:

  • celsius Number

    The celsius value.

  • decimals Number

    The number of decimals.

Returns:

Example:

 MathUtil.celsiusToFahrenheit(0);
 // 32

 MathUtil.celsiusToFahrenheit(100);
 // 212

centimeterToInch
(
  • cm
)
Number public static

Converts centimeters into inches.

Parameters:

Returns:

Example:

NumberUtil.centimeterToInch(1);
// 0.3937

convertToHHMMSS
(
  • seconds
  • showHours
)
String public static

Converts seconds into hour, minutes, seconds.

Parameters:

  • 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

Returns:

Example:

NumberUtil.convertToHHMMSS(33333);
// '09:15:33'

doubleDigitFormat
(
  • num
)
String public static

Formats a number from 0-9 to display with 2 digits.

Parameters:

Returns:

Example:

NumberUtil.doubleDigitFormat(0);
// '00'

NumberUtil.doubleDigitFormat(5);
// '05'

NumberUtil.doubleDigitFormat(9);
// '09'

fahrenheitToCelsius
(
  • fahrenheit
  • decimals
)
Number

Convert Fahrenheit to Celsius.

Parameters:

  • fahrenheit Number

    The fahrenheit value.

  • decimals Number

    The number of decimals.

Returns:

Example:

 MathUtil.fahrenheitToCelsius(32);
 // 0

 MathUtil.fahrenheitToCelsius(212);
 // 100

feetToMeter
(
  • feet
)
Number public static

Converts feet into meters.

Parameters:

Returns:

Example:

NumberUtil.feetToMeter(1);
// 0.3048

formatUnit
(
  • value
  • [decimalPlacement=2]
  • [decimalSeparator='.']
  • [thousandsSeparator=',']
  • [currencySymbol='']
  • [currencySymbolPlacement=0]
)
String public static

Formats a number as a currency string.

Parameters:

  • 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:

String:

Returns the formatted currency.

Example:

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
)
Number public static

Converts inches into centimeters.

Parameters:

Returns:

Example:

NumberUtil.inchToCentimeter(1);
// 2.54

unformatUnit
(
  • value
)
Number public static

Formats a currency string as a number.

Parameters:

  • value String

    The string currency that you want converted into a number.

Returns:

Number:

Returns the number value of the currency string.

Example:

NumberUtil.unformatUnit('$1,234,567.89');
// 1234567.89

NumberUtil.unformatUnit('1.234.567,89 €');
// 1234567.89

NumberUtil.unformatUnit('$-123,456,789.99');
// -123456789.99

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index