RingoJS

Module ringo/utils/numbers

Provides utility functions for working with JavaScript numbers.

Functions


format (number, fmt, locale)

Format number using java.text.DecimalFormat.

Example

>> const numbers = require('ringo/utils/numbers');
>> numbers.format(123, "#,###,##0.00"); // uses the default locale
'123.00'
>> numbers.format(123, "#,###,##0.00", java.util.Locale.GERMAN);
'123,00'
>> numbers.format(123, "#,###,##0.00", java.util.Locale.ENGLISH);
'123.00'

Parameters

Number number

the number

String fmt

the format to apply

java.util.Locale locale

optional locale

Returns

String

the number formatted as string


times (num, fun)

Invoke a function num times, passing 0 .. (this - 1) as argument.

Example

const numbers = require('ringo/utils/numbers');
numbers.times(5, function(i) {
  console.log("#" + i);
});

Parameters

Number num

the number

Function fun

the function to call