6 ## abbreviate(val[, nDecimalDigits, dictionary]):String
8 Abbreviate number to thousands (K), millions (M) or billions (B).
10 The default value for `nDecimalDigits` is `1`.
14 abbreviate(123456); // "123.5K"
15 abbreviate(12345678); // "12.3M"
16 abbreviate(1234567890); // "1.2B"
18 You can set the amount of decimal digits (default is `1`):
20 abbreviate(543); // "0.5K"
21 abbreviate(543, 1); // "0.5K"
22 abbreviate(543, 2); // "0.54K"
23 abbreviate(543, 3); // "0.543K"
25 You can customize the abbreviation by passing a custom "dictionary":
32 function customAbbr(val) {
33 return abbreviate(val, 1, _ptbrDict);
36 customAbbr(123456); // "123.5 mil"
37 customAbbr(12345678); // "12.3 Mi"
38 customAbbr(1234567890); // "1.2 Bi"
42 ## currencyFormat(val[, nDecimalDigits, decimalSeparator, thousandsSeparator]):String
44 Format a number as currency.
48 currencyFormat(1000); // "1,000.00"
49 currencyFormat(1000, 1); // "1,000.0"
50 currencyFormat(1000, 2, ',', '.'); // "1.000,00"
54 ## enforcePrecision(val, nDecimalDigits):Number
56 Enforce a specific amount of decimal digits and also fix floating point
62 enforcePrecision(0.615, 2); // 0.62
63 enforcePrecision(0.625, 2); // 0.63
64 //floating point rounding "error" (rounds to odd number)
65 +(0.615).toFixed(2); // 0.61
66 +(0.625).toFixed(2); // 0.63
72 ES6 `Number.isNaN()`, checks if supplied value is `NaN`.
75 // only returns `true` for `NaN`
79 // everything else is `false`
82 isNaN('asd'); // false
83 isNaN('NaN'); // false
89 Maximum 32-bit signed integer value. `Math.pow(2, 31) - 1`
94 console.log( MAX_INT ); // 2147483647
98 ## MAX_SAFE_INTEGER:Number
100 Maximum safe integer. `Math.pow(2,53) − 1`
105 Maximum 32-bit unsigned integer value. `Math.pow(2, 32) - 1`
110 console.log( MAX_UINT ); // 4294967295
116 Minimum 32-bit signed integer value. `Math.pow(2, 31) * -1`.
121 console.log( MIN_INT ); // -2147483648
127 Returns the "nth" of number. (`"st"`, `"nd"`, `"rd"`, `"th"`)
138 See: [`ordinal()`](#ordinal)
144 Converts number into ordinal form (1st, 2nd, 3rd, 4th, ...)
150 ordinal(14); // "14th"
151 ordinal(21); // "21st"
158 ## pad(n, minLength[, char]):String
160 Add padding zeros if `n.length` < `minLength`.
165 pad(1, 5); // "00001"
166 pad(12, 5); // "00012"
167 pad(123, 5); // "00123"
168 pad(1234, 5); // "01234"
169 pad(12345, 5); // "12345"
170 pad(123456, 5); // "123456"
172 // you can also specify the "char" used for padding
173 pad(12, 5, '_'); // "___12"
176 see: [string/lpad](./string.html#lpad)
180 ## rol(val, shift):Number
182 Bitwise circular shift left.
184 More info at [Wikipedia#Circular_shift](http://en.wikipedia.org/wiki/Circular_shift)
188 ## ror(val, shift):Number
190 Bitwise circular shift right.
192 More info at [Wikipedia#Circular_shift](http://en.wikipedia.org/wiki/Circular_shift)
198 Returns `-1` if value is negative, `0` if the value is `0` and `1` if value is positive. Useful for
211 "Convert" value into an 32-bit integer. Works like `Math.floor` if `val > 0` and
212 `Math.ceil` if `val < 0`.
214 **IMPORTANT:** val will wrap at [number/MIN_INT](#MIN_INT) and
215 [number/MAX_INT](#MAX_INT).
217 Created because most people don't know bitwise operations and also because this
218 feature is commonly needed.
220 [Perf tests](http://jsperf.com/vs-vs-parseint-bitwise-operators/7)
233 ## toUInt(val):Number
235 "Convert" value into an 32-bit unsigned integer.
237 Works like AS3#uint().
239 **IMPORTANT:** val will wrap at 2^32.
247 toUInt(-5.0001); // 4294967291
248 toUInt(Math.pow(2,32) - 0.5); // 4294967295
249 toUInt(Math.pow(2,32) + 0.5); // 0
253 ## toUInt31(val):Number
255 "Convert" value into an 31-bit unsigned integer (since 1 bit is used for sign).
257 Useful since all bitwise operators besides `>>>` treat numbers as signed
260 **IMPORTANT:** val will wrap at 2^31 and negative numbers will be treated as
268 toUInt31(-0.55); // 0
269 toUInt31(-5.0001); // 0
270 toUInt31(Math.pow(2,31) - 0.5); // 21474836470
271 toUInt31(Math.pow(2,31) + 0.5); // 0
275 -------------------------------------------------------------------------------
277 For more usage examples check specs inside `/tests` folder. Unit tests are the
278 best documentation you can get...