# NumberUtil Class

Defined in: `js/util/NumberUtil.js:9`
Module: util
Parent Module: StructureJS

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

## Index

Show: Inherited Protected Private Deprecated

### Methods

- bytesToMegabytes static
- celsiusToFahrenheit
- centimeterToInch static
- convertToHHMMSS static
- doubleDigitFormat static
- fahrenheitToCelsius
- feetToMeter static
- formatUnit static
- inchToCentimeter static
- unformatUnit static

## Methods

### `bytesToMegabytes`
(

- `bytes`

)
Number public static

Defined in `js/util/NumberUtil.js:22`

Converts bytes into megabytes.

#### Parameters:

- `bytes` Number

#### Returns:

Number:

#### Example:

### `celsiusToFahrenheit`
(

- `celsius`
- `decimals`

)
Number

Defined in `js/util/NumberUtil.js:258`

Convert Celsius to Fahrenheit.

#### Parameters:

- `celsius` Number

  The celsius value.

- `decimals` Number

  The number of decimals.

#### Returns:

Number:

#### Example:

     MathUtil.celsiusToFahrenheit(0);
     // 32

     MathUtil.celsiusToFahrenheit(100);
     // 212

### `centimeterToInch`
(

- `cm`

)
Number public static

Defined in `js/util/NumberUtil.js:36`

Converts centimeters into inches.

#### Parameters:

- `cm` Number

#### Returns:

Number:

#### Example:

    NumberUtil.centimeterToInch(1);
    // 0.3937

### `convertToHHMMSS`
(

- `seconds`
- `showHours`

)
String public static

Defined in `js/util/NumberUtil.js:82`

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:

String:

#### Example:

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

### `doubleDigitFormat`
(

- `num`

)
String public static

Defined in `js/util/NumberUtil.js:112`

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

#### Parameters:

- `num` Number

#### Returns:

String:

#### Example:

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

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

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

### `fahrenheitToCelsius`
(

- `fahrenheit`
- `decimals`

)
Number

Defined in `js/util/NumberUtil.js:226`

Convert Fahrenheit to Celsius.

#### Parameters:

- `fahrenheit` Number

  The fahrenheit value.

- `decimals` Number

  The number of decimals.

#### Returns:

Number:

#### Example:

     MathUtil.fahrenheitToCelsius(32);
     // 0

     MathUtil.fahrenheitToCelsius(212);
     // 100

### `feetToMeter`
(

- `feet`

)
Number public static

Defined in `js/util/NumberUtil.js:66`

Converts feet into meters.

#### Parameters:

- `feet` Number

#### Returns:

Number:

#### Example:

    NumberUtil.feetToMeter(1);
    // 0.3048

### `formatUnit`
(

- `value`
- `[decimalPlacement=2]`
- `[decimalSeparator='.']`
- `[thousandsSeparator=',']`
- `[currencySymbol='']`
- `[currencySymbolPlacement=0]`

)
String public static

Defined in `js/util/NumberUtil.js:173`

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

Defined in `js/util/NumberUtil.js:51`

Converts inches into centimeters.

#### Parameters:

- `inch` Number

#### Returns:

Number:

#### Example:

    NumberUtil.inchToCentimeter(1);
    // 2.54

### `unformatUnit`
(

- `value`

)
Number public static

Defined in `js/util/NumberUtil.js:136`

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