{"id":22703539,"url":"https://github.com/shrpne/pretty-num","last_synced_at":"2025-10-25T18:34:49.976Z","repository":{"id":32798344,"uuid":"142916367","full_name":"shrpne/pretty-num","owner":"shrpne","description":"Lightweight module to convert number to a pretty human readable string.","archived":false,"fork":false,"pushed_at":"2025-03-27T17:03:53.000Z","size":1323,"stargazers_count":14,"open_issues_count":6,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T10:42:02.602Z","etag":null,"topics":["exponential","format","human","number","precision","pretty","readable","string","thousands"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shrpne.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-30T18:59:02.000Z","updated_at":"2025-03-27T17:03:56.000Z","dependencies_parsed_at":"2023-01-14T22:16:06.232Z","dependency_job_id":null,"html_url":"https://github.com/shrpne/pretty-num","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrpne%2Fpretty-num","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrpne%2Fpretty-num/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrpne%2Fpretty-num/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrpne%2Fpretty-num/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shrpne","download_url":"https://codeload.github.com/shrpne/pretty-num/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248691779,"owners_count":21146442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exponential","format","human","number","precision","pretty","readable","string","thousands"],"created_at":"2024-12-10T08:11:09.786Z","updated_at":"2025-10-25T18:34:49.897Z","avatar_url":"https://github.com/shrpne.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pretty-num\n\n[![NPM Package](https://img.shields.io/npm/v/pretty-num.svg?style=flat-square)](https://www.npmjs.org/package/pretty-num)\n[![Minified Size](https://img.shields.io/bundlephobia/min/pretty-num.svg?style=flat-square)](https://bundlephobia.com/result?p=pretty-num)\n[![Build Status](https://img.shields.io/travis/com/shrpne/pretty-num/master.svg?style=flat-square)](https://travis-ci.com/shrpne/pretty-num)\n[![Coverage Status](https://img.shields.io/coveralls/github/shrpne/pretty-num/master.svg?style=flat-square)](https://coveralls.io/github/shrpne/pretty-num?branch=master)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://github.com/shrpne/pretty-num/blob/master/LICENSE)\n\nLightweight module to convert number to a pretty human readable string.\n\nIncludes:\n- [from-exponential](https://github.com/shrpne/from-exponential) - remove exponential notation\n- [thousands](https://github.com/scurker/thousands) - add thousands separators\n- toPrecision - adjust precision of decimal part\n- stripZeros - strip unnecessary leading and trailing zeros\n\n\n## Install\n\n```\nnpm install pretty-num\n```\n\n\n## Usage\n\n```js\nimport prettyNum, {PRECISION_SETTING} from 'pretty-num';\n\nprettyNum(12.123e-10); // =\u003e '0.0000000012123'\nprettyNum(0.00123456, {precision: 3}); // =\u003e '0.001'\nprettyNum(0.00123456, {precision: 3, precisionSetting: PRECISION_SETTING.REDUCE_SIGNIFICANT}); // =\u003e '0.00123'\nprettyNum(12345678.12345, {thousandsSeparator: ' '}); // =\u003e '12 345 678.12345'\nprettyNum(12345678.12345, {decimalSeparator: ','}); // =\u003e '12345678,12345'\nprettyNum('00123456789.12300e-2', {precision: 3, thousandsSeparator: ' '}); // =\u003e '1 234 567.891'\n```\n\n## Options\n\n### `thousandsSeparator`\nDefines the thousand grouping separator character\n```js\nprettyNum(12345678.12345, {thousandsSeparator: ' '}); \n// =\u003e '12 345 678.12345'\nprettyNum(12345678.12345, {thousandsSeparator: ','}); \n// =\u003e '12,345,678.12345'\n```\n\n### `separateOneDigit`\nShould number less than 10000 (e.g. 9999) to be separated, `true` by default\n```js\nprettyNum(1234, {thousandsSeparator: ' ', separateOneDigit: true});\n// =\u003e '1 234'\nprettyNum(1234, {thousandsSeparator: ' ', separateOneDigit: false});\n// =\u003e '1234'\n```\n\n### `precision`\nNumber of decimal digits to keep when rounding. Pass falsey value to not change precision.\n\n### `decimalSeparator`\nSeparator between the integer part and the fractional part\n\n### `precisionSetting`\nHow to work with precision:\n\n#### Reduce\n`1`, `REDUCE` (default) - reduce precision to specified number of decimal digits, strip unnecessary ending zeros; \n```js\nprettyNum(0.01023456, {precision: 3});\n// =\u003e '0.01'\nprettyNum(0.00001203456, {precision: 3});\n// =\u003e '0'\n```\n\n#### Reduce significant\n`2`, `REDUCE_SIGNIFICANT` - reduce precision to specified number of significant decimal digits, strip unnecessary ending zeros. Useful when rounding small values and they should not be rounded to 0\n```js\nprettyNum(0.01023456, {precision: 3, precisionSetting: PRECISION_SETTING.REDUCE_SIGNIFICANT});\n// =\u003e '0.0102'\nprettyNum(0.00001203456, {precision: 3, precisionSetting: PRECISION_SETTING.REDUCE_SIGNIFICANT});\n// =\u003e '0.000012'\n```  \n\n#### Fixed\n`3`, `FIXED` - set precision to specified number of decimal digits, pad with ending zeros if needed.\n```js\nprettyNum(0.01023456, {precision: 3, precisionSetting: PRECISION_SETTING.FIXED});\n// =\u003e '0.010'\nprettyNum(0.00001203456, {precision: 3, precisionSetting: PRECISION_SETTING.FIXED});\n// =\u003e '0.000'\n``` \n\n#### Increase\n`4`, `INCREASE` - pad with ending zeros to increase precision to specified number of decimal digits.\n```js\nprettyNum(0.01, {precision: 4, precisionSetting: PRECISION_SETTING.INCREASE});\n// =\u003e '0.0100'\nprettyNum(12, {precision: 4, precisionSetting: PRECISION_SETTING.INCREASE});\n// =\u003e '12.0000'\nprettyNum(12.123456, {precision: 4, precisionSetting: PRECISION_SETTING.INCREASE});\n// =\u003e '12.123456'\n``` \n\n\n### `roundingMode`\nSpecifies a rounding behavior for numerical operations capable of discarding precision. Following rounding modes are supported:\n\n- `1`, `UP` - Rounding mode to round away from zero.\n- `2`, `DOWN` - Rounding mode to round towards zero.\n- `3`, `CEIL` - Rounding mode to round towards positive infinity.\n- `4`, `FLOOR` - Rounding mode to round towards negative infinity.\n- `5`, `HALF_UP` - Rounding mode to round towards \"nearest neighbor\" unless both neighbors are equidistant, in which case round up.\n- `6`, `HALF_DOWN` - Rounding mode to round towards \"nearest neighbor\" unless both neighbors are equidistant, in which case round down.\n- `7`, `HALF_EVEN` - Rounding mode to round towards the \"nearest neighbor\" unless both neighbors are equidistant, in which case, round towards the even neighbor.\n\nExtensive description of the modes can be found at [Rounding Modes](https://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html)\n\n```js\nprettyNum(123.657, {precision: 1, roundingMode: ROUNDING_MODE.DOWN}); // =\u003e \"123.6\"\nprettyNum(123.657, {precision: 2, roundingMode: ROUNDING_MODE.CEIL}); // =\u003e \"123.66\"\n```\n\n\n## Comparison\n\n- This module: [![Minified Size](https://img.shields.io/bundlephobia/min/pretty-num.svg?style=flat-square\u0026label=minified)](https://bundlephobia.com/result?p=pretty-num) [![Minified Size](https://img.shields.io/bundlephobia/minzip/pretty-num.svg?style=flat-square\u0026label=gzipped)](https://bundlephobia.com/result?p=pretty-num)\n- [`js-big-decimal`](https://github.com/royNiladri/js-big-decimal): [![Minified Size](https://img.shields.io/bundlephobia/min/js-big-decimal.svg?style=flat-square\u0026label=minified)](https://bundlephobia.com/result?p=js-big-decimal) [![Minified Size](https://img.shields.io/bundlephobia/minzip/js-big-decimal.svg?style=flat-square\u0026label=gzipped)](https://bundlephobia.com/result?p=js-big-decimal) Math operations are supported, `REDUCE_SIGNIFICANT`, `FIXED` and `INCREASE` `precisionSetting` are not supported\n- [`big.js`](https://github.com/MikeMcl/big.js): [![Minified Size](https://img.shields.io/bundlephobia/min/big.js.svg?style=flat-square\u0026label=minified)](https://bundlephobia.com/result?p=big.js) [![Minified Size](https://img.shields.io/bundlephobia/minzip/big.js.svg?style=flat-square\u0026label=gzipped)](https://bundlephobia.com/result?p=big.js) Math operations are supported, some `precisionSetting` are not supported, `CEIL`, `FLOOR` and `HALF_DOWN` `roundingMode` are not supported.\n\n- [`bignumber.js`](https://github.com/MikeMcl/bignumber.js): [![Minified Size](https://img.shields.io/bundlephobia/min/bignumber.js.svg?style=flat-square\u0026label=minified)](https://bundlephobia.com/result?p=bignumber.js) [![Minified Size](https://img.shields.io/bundlephobia/minzip/bignumber.js.svg?style=flat-square\u0026label=gzipped)](https://bundlephobia.com/result?p=bignumber.js) Math operations are supported, more rounding modes are supported, some `precisionSetting` are not supported.\n\n\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshrpne%2Fpretty-num","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshrpne%2Fpretty-num","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshrpne%2Fpretty-num/lists"}