Class
caplin.core

Number

Utility methods for numbers

Constructor Summary

Attributes Name and Description
caplin.core.Number()

Method Summary

Attributes Name and Description
<static> boolean isNumber(Object n)

<static> Number log10(Number n)

Logarithm to base 10.

<static> String pad(Number nValue, Number nLength)

Pads the integer part of a number with zeros to reach the specified length.

<static> Number round(Number n)

Rounds a floating point number

<static> int sgn(Number n)

Returns a numeric representation of the sign on the number.

<static> String toFixed(Number n, Number nDp)

Formats the number to the specified number of decimal places.

<static> String toPrecision(Number n, Number nSf)

Formats the number to the specified number of significant figures.

<static> String toRounded(Number n, Number nRounding)

Formats the number to the specified number of decimal places, omitting any trailing zeros.

Constructor Detail

caplin.core.Number()

Method Detail

<static> boolean isNumber(Object n)

Parameters
Object n
Returns
true for numbers and their string representations and false for other values including non-numeric strings, null, Infinity, NaN.

<static> Number log10(Number n)

Logarithm to base 10.

Parameters
Number n The number (or a number as a string)
Returns
The logarithm to base 10.

<static> String pad(Number nValue, Number nLength)

Pads the integer part of a number with zeros to reach the specified length.

Parameters
Number nValue The number (or a number as a string)
Number nLength The required length of the number
Returns
The formatted number

<static> Number round(Number n)

Rounds a floating point number

Parameters
Number n The number (or a number as a string)
Returns
The formatted number

<static> int sgn(Number n)

Returns a numeric representation of the sign on the number.

Parameters
Number n The number (or a number as a string)
Returns
1 for positive values, -1 for negative values, or the original value for zero and non-numeric values

<static> String toFixed(Number n, Number nDp)

Formats the number to the specified number of decimal places.

Parameters
Number n The number (or a number as a string)
Number nDp The number of decimal places
Returns
The formatted number

<static> String toPrecision(Number n, Number nSf)

Formats the number to the specified number of significant figures. This fixes the bugs in the native Number function of the same name that are prevalent in various browsers. If the number of significant figures is less than one, then the function has no effect.

Parameters
Number n The number (or a number as a string)
Number nSf The number of significant figures
Returns
The formatted number

<static> String toRounded(Number n, Number nRounding)

Formats the number to the specified number of decimal places, omitting any trailing zeros.

Parameters
Number n The number (or a number as a string)
Number nRounding The number of decimal places to round
Returns
The rounded number.