{"id":15649815,"url":"https://github.com/nfriedly/approximate-number","last_synced_at":"2025-04-05T18:05:27.745Z","repository":{"id":22929068,"uuid":"26278165","full_name":"nfriedly/approximate-number","owner":"nfriedly","description":"Converts numbers into a more human-friendly format. E.g. 123456 becomes 123k. Similar to `ls -lh` or Stack Overflow's reputation numbers. ","archived":false,"fork":false,"pushed_at":"2025-02-18T23:35:16.000Z","size":182,"stargazers_count":37,"open_issues_count":5,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T17:02:21.976Z","etag":null,"topics":["abbreviations","approximation","estimate","estimation","floor","human-computer-interaction","readability","rounding"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/approximate-number","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nfriedly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-06T16:13:07.000Z","updated_at":"2024-06-17T20:01:45.000Z","dependencies_parsed_at":"2022-09-11T07:01:20.495Z","dependency_job_id":"60ffafea-6b93-49d2-9aa2-98f969a6d6ae","html_url":"https://github.com/nfriedly/approximate-number","commit_stats":{"total_commits":62,"total_committers":6,"mean_commits":"10.333333333333334","dds":"0.30645161290322576","last_synced_commit":"adfc443aaf5a9c4d48a851283376916880db7286"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriedly%2Fapproximate-number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriedly%2Fapproximate-number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriedly%2Fapproximate-number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfriedly%2Fapproximate-number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nfriedly","download_url":"https://codeload.github.com/nfriedly/approximate-number/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378138,"owners_count":20929296,"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":["abbreviations","approximation","estimate","estimation","floor","human-computer-interaction","readability","rounding"],"created_at":"2024-10-03T12:32:08.248Z","updated_at":"2025-04-05T18:05:27.710Z","avatar_url":"https://github.com/nfriedly.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Approximate Number\n\n[![CI](https://github.com/nfriedly/approximate-number/actions/workflows/ci.yml/badge.svg)](https://github.com/nfriedly/approximate-number/actions/workflows/ci.yml)\n[![npm version](https://badge.fury.io/js/approximate-number.svg)](https://www.npmjs.com/package/approximate-number)\n[![npm downloads](https://img.shields.io/npm/dm/approximate-number)](https://www.npmjs.com/package/approximate-number)\n\nAbbreviates numbers into a more human-friendly format, similar to `ls`'s `--human-readable` flag (`ls -lh`) or Stack\nOverflow's reputation numbers. For example, 123456 becomes '123k'.\n\nWorks in Node.js and in browsers.\n\n```js\nvar approx = require('approximate-number');\n\nconsole.log(approx(1234));\n//\u003e 1.2k\n\nconsole.log(approx(12345));\n//\u003e 12k\n\nconsole.log(approx(1234, {decimal: false}));\n//\u003e 1k\n\nconsole.log(approx(1234, {decimal: ','}));\n//\u003e 1,2k\n\nconsole.log('My Stack Overflow reputation is %s.', approx(3671, {\n  min10k: true\n}));\n//\u003e My Stack Overflow reputation is 3,671.\n\nconsole.log('The US national debt is %s.', approx(19939034457936, {\n  prefix: '$', \n  capital: true, \n  round: true\n}));\n// \u003e The US national debt is $20T.\n\n// Truncates/floors numbers by default\napprox(9999);\n// \u003e '9.9k'\n\n// Set `round: true` to round instead of floor.\napprox(9999,{round: true});\n// \u003e '10k'\n\n```\n\n## Getting Started\n\n### Node.js\n\nInstall node module with: `npm install --save approximate-number`\n\n```js\nvar approx = require('approximate-number');\napprox(123456) // 123k\n```\n\n### Bower\n\nInstall with: `bower install approximate-number`\n\n```html\n\u003cscript src=\"/bower_components/approximate-number/lib/approximate-number.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nalert(approximateNumber(1234567890)); // 1.2b\n\u003c/script\u003e\n```\n\n### Browser usage without a package manager\n\nGrab the latest [approximate-number.js](https://github.com/nfriedly/approximate-number/blob/master/lib/approximate-number.js) and copy it onto your site.\n\n## Options\n\n* **separator** {String|Boolean} Default = `','`. Thousands separator - set to a string (e.g. '.') to use that string or false to not use any separator.\n* **decimal** {String|Boolean} Default = `'.'`. Decimal - set to a string (e.g. ',') to use that or set to false to avoid outputting values with a decimal.\n* **round** {Boolean} Default = `false`. Round numbers off rather than flooring/truncating. When true, 105000 would become '11m', when false it becomes '10m'.\n* **min10k** {Boolean} Default = `false`. Do not abbreviate numbers below 10000. E.g. 9999 would become '9,999' rather than '9k'. (Stack Overflow-style).\n* **prefix** {String} Default = `''`. Optional string to prepend to the value, e.g. '$'.\n* **suffix** {String} Default = `''`. Optional string to append to the value, e.g. '%'.\n* **capital** {Boolean} Default = `false`. Set to true to use capital letters, e.g. 3.9M instead of 3.9m\n* **precision** {Number} Default = undefined. Number of significant digits. Must be greater than 0. Use of this option forces rounding.\n\n## V2.1 Changes\n* Added precision\n\n## V2 Changes\n\n* Added optional configuration object\n* Changed default from rounding to truncation. Override with `options.round=true`.\n* Started abbreviating numbers between 1000 and 9999 by default. Override with `options.min10k=true`.\n* Added trillions support.\n* Dropped cli support.\n\n## License\n\nCopyright (c) 2014 Nathan Friedly  \nLicensed under the MIT license.\n\n\n[tests]: https://github.com/nfriedly/approximate-number/blob/master/test/approximate-number_test.js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfriedly%2Fapproximate-number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnfriedly%2Fapproximate-number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfriedly%2Fapproximate-number/lists"}