https://github.com/atwill007/number-magic
JavaScript number commonly used number conversion
https://github.com/atwill007/number-magic
comma conversion magic number percentage random utils
Last synced: about 2 months ago
JSON representation
JavaScript number commonly used number conversion
- Host: GitHub
- URL: https://github.com/atwill007/number-magic
- Owner: atwill007
- License: mit
- Created: 2020-02-29T14:56:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-10T11:32:02.000Z (about 3 years ago)
- Last Synced: 2026-04-30T08:47:08.114Z (about 2 months ago)
- Topics: comma, conversion, magic, number, percentage, random, utils
- Language: TypeScript
- Homepage:
- Size: 308 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# number-magic
A useful number utils library
## Docs
English | [简体中文](./docs/zh-cn/README.zh-CN.md)
## Install
[number-magic](https://www.npmjs.com/package/number-magic)
```
npm install number-magic
```
or
```
pnpm install number-magic
```
or
```
yarn add number-magic
```
## Use
```js
import {
comma,
toFixed,
percentage,
idxList,
randomInt,
capital,
precise,
isNumber,
} from 'number-magic'
comma(1234567.123) // 1,234,567.123
toFixed(1234567.123) // 1234567.12
toFixed(123.123, 4) // 123.1230
toFixed(12345.12345, 4) // 12345.1235
percentage(0.6666, 3) // 66.660%
percentage(0.555555, 3) // 55.556%
idxList(6, 1) // [ 1, 2, 3, 4, 5, 6 ]
randomInt(1.1, 2.1) // 2
capital(123123.12) // 拾贰万叁千壹百贰拾叁元壹角贰分
const numb = 0.1 + 0.2 // 0.30000000000000004
precise(numb) // 0.3
isNumber('hi') // false
isNumber(NaN) // false
isNumber(Math.PI) // true
isNumber(2 ** 53) // true
isNumber(2 ** 53, true) // false
// ...
// See unit tests for more
```
## You are welcome to join the project by proposing PR