-
Notifications
You must be signed in to change notification settings - Fork 192
Number API
IgorTimofeev edited this page Jan 9, 2019
·
4 revisions
This library allows to work with numeric data in different ways: to round them to decimal places, to shorten them with adding postfixes or to get digit count.
| Contents |
|---|
| number.round |
| number.roundToDecimalPlaces |
| number.shorten |
| number.getDigitCount |
Rounds the number to the nearest integer and returns the result:
number.round(1.3)
number.round(1.7)
number.round(-1.9)> 1.0
> 2.0
> -2.0Rounds the number to the nearest integer, limiting the result to the specified number of decimal places and returns the result:
number.roundToDecimalPlaces(1.23456789, 2)
number.roundToDecimalPlaces(1.23456789, 4)> 1.23
> 1.2345Converts given value to a string with K, M, G, T, P, E, Z or Y postfixes in dependence on the size of the number, leaving given count of decimal places:
number.shorten(123, 2)
number.shorten(1234, 2)
number.shorten(12345, 2)
number.shorten(123456, 2)
number.shorten(1234567, 2)
number.shorten(12345678, 2)
number.shorten(123456789, 2)
number.shorten(1234567891, 2)> "123"
> "1.23K"
> "12.34K"
> "123.45K"
> "1.23M"
> "12.34M"
> "123.45M"
> "1.23G"Returns count of digits in decimal number:
number.getDigitCount(123)
number.getDigitCount(123456)> 3
> 6