{"id":22122857,"url":"https://github.com/andreaspizsa/parse-decimal-number","last_synced_at":"2026-01-11T22:58:58.876Z","repository":{"id":21399104,"uuid":"24716996","full_name":"AndreasPizsa/parse-decimal-number","owner":"AndreasPizsa","description":"🏧 Parse a decimal number with i18n format support (localized decimal points and comma separators)","archived":false,"fork":false,"pushed_at":"2025-04-01T10:24:18.000Z","size":52,"stargazers_count":38,"open_issues_count":17,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T19:27:55.035Z","etag":null,"topics":["cldr","coffeescript","i10n","i18n","input-validation","javascript","localization","number-format","number-input","numeral","parses-numbers"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/parse-decimal-number","language":"CoffeeScript","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/AndreasPizsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-10-02T11:53:04.000Z","updated_at":"2025-02-17T22:19:56.000Z","dependencies_parsed_at":"2023-01-13T21:27:17.159Z","dependency_job_id":"552597c7-ab03-48c9-967d-c0443e4d4922","html_url":"https://github.com/AndreasPizsa/parse-decimal-number","commit_stats":{"total_commits":42,"total_committers":11,"mean_commits":"3.8181818181818183","dds":0.5952380952380952,"last_synced_commit":"4eed4beadfe1de4b87789e8034b36f061c496375"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreasPizsa%2Fparse-decimal-number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreasPizsa%2Fparse-decimal-number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreasPizsa%2Fparse-decimal-number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreasPizsa%2Fparse-decimal-number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndreasPizsa","download_url":"https://codeload.github.com/AndreasPizsa/parse-decimal-number/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249524,"owners_count":20908212,"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":["cldr","coffeescript","i10n","i18n","input-validation","javascript","localization","number-format","number-input","numeral","parses-numbers"],"created_at":"2024-12-01T15:28:04.187Z","updated_at":"2025-04-04T21:07:04.748Z","avatar_url":"https://github.com/AndreasPizsa.png","language":"CoffeeScript","readme":"# parse-decimal-number ![Travis](https://img.shields.io/travis/AndreasPizsa/parse-decimal-number.svg?style=flat-square) [![Coverage Status](https://img.shields.io/coveralls/AndreasPizsa/parse-decimal-number.svg?style=flat-square)](https://coveralls.io/github/AndreasPizsa/parse-decimal-number?branch=master) ![Downloads](https://img.shields.io/npm/dm/parse-decimal-number.svg?style=flat-square)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FAndreasPizsa%2Fparse-decimal-number.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FAndreasPizsa%2Fparse-decimal-number?ref=badge_shield)\n\u003e Parse a decimal number with i18n format support (localized decimal points and thousands separators)\n\n## About\nOK, let’s fix international numbers **parsing** and **validation** once and forever. I got the inspiration for this in a UI project because somehow the libraries we used didn’t do a great job, so I wrote my own parser, and this is a more polished version of it.\n\nThese are the design goals:\n\n* **Simple.** String in, float out, done. ✓\n* **Accurate.** Parses numbers and returns `NaN` for non-numbers. (=good for input validation) ✓\n* **Lightweight.** (\u003c1k minified) ✓\n* **Complete.** No external dependencies ✓\n* **Solid.** 100% Code Coverage ✓\n* **CLDR Support.** Supports `cldr` data ✓\n\nIn it’s simplest form, you just use it as a `parseFloat` replacement.\n\n## Install\n#### Install with [npm](https://npmjs.org)\n\n```bash\nnpm i parse-decimal-number --save\n```\n\n## Usage\n```javascript\nparseDecimalNumber = require('parse-decimal-number');\nconsole.log(parseDecimalNumber('12,345,678.90'));\n// -\u003e 12345678.90\n\nconsole.log(parseDecimalNumber('12.345.678,90','.,'));\n// -\u003e 12345678.90\n```\n\n### parseDecimalNumber(string _[,options]_)\nReturns a `float` representation of _string_ or `NaN` if _string_ is not a parseable number. Use the optional `options` parameter to specify the thousands and decimal point characters.\n\n#### Parameters\n**string** A String that is supposed to contain a number.\n\n**options** _optional_ A string, array or hash with thousands and decimal separators.\n\n* _String_\n  a two-character string consisting of the thousands character followed by the decimal point character, e.g. `',.'`\n\n* _Array_\n  An array of two elements, the first being the thousands character, the second being the decimal point character, e.g. `['.',',']`\n\n* _Hash_ with the following elements (this is compatible with NumeralJS)\n  * **`thousands`** thousands separator character. _Default:_ `,`\n  * **`decimal`** decimal point character. _Default:_ `.`\n\n**enforceGroupSize** A boolean indicating whether to support that individual groups between the thousands character are exactly 3 digits\n\n#### Examples\n\n```javascript\nconsole.log(parseDecimalNumber('12.345.678,90'));\n// -\u003e 12345678.90\n```\n\n###### String `options`\n```javascript\nconsole.log(parseDecimalNumber('12.345.678,90','.,'));\n// -\u003e 12345678.90\n```\n\n###### Array `options`\n```javascript\nconsole.log(parseDecimalNumber('12.345.678,90',['.',',']));\n// -\u003e 12345678.90\n```\n\n###### Hash `options`\n```javascript\nvar customSeparators = {thousands:'.',decimal:','};\nconsole.log(parseDecimalNumber('12.345.678,90',customSeparators));\n// -\u003e 12345678.90\n```\n\n### parseDecimalNumber.withOptions(options)\nReturns a _function_ that will take a _string_ as an argument and return a `float` or `NaN`, just like `parseDecimalNumber`.\n\n#### Example\n\n```javascript\n  const cldr = require('cldr');\n\n  const locale = 'de_DE';\n  const options = cldr.extractNumberSymbols(locale);\n\n  const parse = parseDecimalNumber.withOptions(options);\n\n  parse('123.456.789,0123'); // -\u003e 123456789.0123\n```\n\n\n### Setting and Resetting Default Options\n\n##### parseDecimalNumber.setOptions\nSet the default thousands and decimal characters that are used when no options are passed to `parseDecimalNumber`.\n\n```javascript\nvar defaultSeparators = {thousands:'.',decimal:','};\nparseDecimalNumber.setOptions(defaultSeparators);\n\nconsole.log(parseDecimalNumber('12.345.678,90'));\n// -\u003e 12345678.90\n```\n\n\n##### parseDecimalNumber.factorySettings\nhas the same effect as `parseDecimalNumber.setOptions({thousands:',',decimal:'.'};)`\n\n## Using with `cldr`\n\nYou can easily apply CLDR data using the [`cldr`](https://www.npmjs.com/package/cldr) package:\n\n```javascript\n  const cldr = require('cldr');\n\n  parseDecimalNumber(\n    '12.345.678,90',\n    cldr.extractNumberSymbols('de_DE')\n  );\n```\n\n\n## Using with Numeral.js\n[Numeral.js](http://numeraljs.com/) is good at formatting numbers and comes with an extensive set of locale data that you can use with `parse-decimal-number`.\n\nIf you use `numeral` in your project, you can use their locale data as follows:\n\n```javascript\nparseDecimalNumber('12.345.678,90', numeral.localeData('de').delimiters);\n// -\u003e 12345678.9\n```\n\nYou can of course use the same data to set the default values for `parse-decimal-number`:\n\n```javascript\nparseDecimalNumber.setOptions(numeral.localeData('de').delimiters);\nparseDecimalNumber('12.345.678,90');\n// -\u003e 12345678.9\n```\n\nDone :relaxed:\n\n\n## Related Projects\nTo keep this project as small and modular as possible, the locale data itself has been left out of this library. If you need locale date, other projects might be helpful:\n\n* [cldr](https://www.npmjs.com/package/cldr)\n* [Numeral](http://numeraljs.com)\n* [jsi18n](https://github.com/marcoscaceres/jsi18n)\n* [Unicode Common Locale Data Repository](http://cldr.unicode.org/index/downloads/latest)\n* [Wikipedia](http://en.wikipedia.org/wiki/Decimal_mark#Examples_of_use)\n\n\n## Running tests\n{%= include(\"tests\") %}\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality, and please re-build the documentation with [gulp-verb](https://github.com/assemble/gulp-verb) before submitting a pull request.\n\n\n## Author\n\n**Andreas Pizsa (http://github.com/AndreasPizsa)**\n\n+ [github/AndreasPizsa](https://github.com/AndreasPizsa)\n+ [twitter/AndreasPizsa](http://twitter.com/AndreasPizsa)\n\n## License\nCopyright (c) 2017 Andreas Pizsa (http://github.com/AndreasPizsa), contributors.  \n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FAndreasPizsa%2Fparse-decimal-number.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FAndreasPizsa%2Fparse-decimal-number?ref=badge_large) [![Greenkeeper badge](https://badges.greenkeeper.io/AndreasPizsa/parse-decimal-number.svg)](https://greenkeeper.io/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreaspizsa%2Fparse-decimal-number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreaspizsa%2Fparse-decimal-number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreaspizsa%2Fparse-decimal-number/lists"}