{"id":27483523,"url":"https://github.com/seccomiro/safe-decimals","last_synced_at":"2025-04-16T15:49:42.255Z","repository":{"id":65492283,"uuid":"201969163","full_name":"seccomiro/safe-decimals","owner":"seccomiro","description":"A Node.js module that fixes the binary floating-point rounding \"error\" at the 17th decimal place of JavaScript numbers","archived":false,"fork":false,"pushed_at":"2019-08-12T19:14:42.000Z","size":2,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-09T06:36:26.002Z","etag":null,"topics":["floating-point-arithmetic","javascript","nodejs"],"latest_commit_sha":null,"homepage":null,"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/seccomiro.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}},"created_at":"2019-08-12T16:34:31.000Z","updated_at":"2023-09-18T15:29:57.000Z","dependencies_parsed_at":"2023-01-25T19:35:13.185Z","dependency_job_id":null,"html_url":"https://github.com/seccomiro/safe-decimals","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seccomiro%2Fsafe-decimals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seccomiro%2Fsafe-decimals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seccomiro%2Fsafe-decimals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seccomiro%2Fsafe-decimals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seccomiro","download_url":"https://codeload.github.com/seccomiro/safe-decimals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249256906,"owners_count":21239076,"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":["floating-point-arithmetic","javascript","nodejs"],"created_at":"2025-04-16T15:49:41.776Z","updated_at":"2025-04-16T15:49:42.245Z","avatar_url":"https://github.com/seccomiro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Safe Decimals\n\n**Safe Decimals** is a Node.js module that fixes the binary floating-point rounding \"error\" at the 17th decimal place of JavaScript numbers.\n\nIt does this using the simple and widespread *multiply-round-divide* technique.\n\n## Installation\n\nTo start using Safe Decimals in your Node.js projects, first just need to install it through NPM:\n\n```bash\nnpm i safe-decimals --save\n```\n\n## Requiring the module\n\nIn order to use it, you have to import it in your code:\n\n```javascript\nrequire('safe-decimals');\n```\n\n**P.S. 1** You don't need to store it on any variable, because Safe Decimals module doesn't export anything.\n\n**P.S. 2** Safe Decimals will inject a function into the `Number` prototype. So you should require it in your code as soon as possible.\n\n## How to use\n\nOnce imported, the module automatically provides a `safe()` function for all the `Number`s:\n\n```javascript\nconst x = 0.1 + 0.2; // This will evaluate \"x\" as 0.30000000000000004 instead of 0.3\nconst newX = x.safe(); // newX == 0.3\n```\n\nPlease note that Safe Decimals will never mutate your original number, so you can safely use it over any variable and store the result into a new one.\n\n## Notes\n\nSafe Decimals will work great if you don't need more than 15 decimals places. I think that's almost 100% of the cases. If you need more than that, you should look for another module that handles big decimals.\n\nPlease keep in mind that we shouldn't touch the built-in prototypes, so use Safe Decimals at your own risk.\n\nThe *multiply-round-divide* technique is a well-known workaround. This module just packs it into a Node.js module.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseccomiro%2Fsafe-decimals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseccomiro%2Fsafe-decimals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseccomiro%2Fsafe-decimals/lists"}