{"id":24539979,"url":"https://github.com/codeandcats/reliable-round","last_synced_at":"2025-07-28T07:09:24.825Z","repository":{"id":33723313,"uuid":"157199308","full_name":"codeandcats/reliable-round","owner":"codeandcats","description":"A rounding library for JavaScript that behaves predictably (unlike Math.round, Math.floor, Math.ceil).","archived":false,"fork":false,"pushed_at":"2023-01-05T16:14:35.000Z","size":1081,"stargazers_count":9,"open_issues_count":19,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-20T01:34:39.096Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/codeandcats.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-12T10:54:28.000Z","updated_at":"2023-11-24T08:49:27.000Z","dependencies_parsed_at":"2023-01-15T02:13:00.943Z","dependency_job_id":null,"html_url":"https://github.com/codeandcats/reliable-round","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/codeandcats/reliable-round","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeandcats%2Freliable-round","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeandcats%2Freliable-round/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeandcats%2Freliable-round/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeandcats%2Freliable-round/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeandcats","download_url":"https://codeload.github.com/codeandcats/reliable-round/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeandcats%2Freliable-round/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267476285,"owners_count":24093472,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-01-22T17:17:33.107Z","updated_at":"2025-07-28T07:09:24.803Z","avatar_url":"https://github.com/codeandcats.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reliable-round\n\nA reliable rounding library for JavaScript/TypeScript that actually behaves predictably (unlike Math.round).\n\n[![npm version](https://badge.fury.io/js/reliable-round.svg)](https://badge.fury.io/js/reliable-round)\n[![Build Status](https://travis-ci.org/codeandcats/reliable-round.svg?branch=master)](https://travis-ci.org/codeandcats/reliable-round)\n[![Coverage Status](https://coveralls.io/repos/github/codeandcats/reliable-round/badge.svg?branch=master)](https://coveralls.io/github/codeandcats/reliable-round?branch=master)\n\n## Install\n\n```sh\nnpm install reliable-round --save\n```\n\n## Usage\n\n```javascript\nimport { round } from \"reliable-round\";\n\nconsole.log(round(1.005)); // Rounds to a whole integer, returning 1\n\nconsole.log(round(1.005, 2)); // Rounds to 2 decimal places returning 1.01\n```\n\n## Why do I need this?\n\nBecause JavaScript floating point math often results in quirky and unpredictable results.\n\nThe classic JS WTF example is:\n\n```javascript\nconsole.log(0.1 + 0.2);\n\n// Evaluates to 0.30000000000000004\n```\n\nMaybe not what you expected right?\n\nAs for rounding, lets say you need to round to 2 decimal places then you can create your own function like this:\n\n```javascript\nfunction roundToTwoDecimalPlaces(value) {\n  return Math.round(value * 100) / 100;\n}\n\nconsole.log(roundToTwoDecimalPlaces(1.006));\n\n// Returns 1.01 - Correct!\n```\n\nAt first glace, the output of the above function looks correct. But unfortunately its only correct some of the time!\n\n```javascript\nconsole.log(roundToTwoDecimalPlaces(1.005));\n\n// Returns 1 - Wrong!\n\n// The correct answer is 1.01\n```\n\nIf you deal with rounding many floats in JS you will inevitably encounter many quirky inconsistencies like this.\n\n[**reliable-round**](https://www.npmjs.com/package/reliable-round) to the rescue!\n\n```javascript\nimport { round } from \"reliable-round\";\n\nconsole.log(round(1.005, 2));\n\n// Correctly returns 1.01\n```\n\nWhile you will get predictable, reliable results using `reliable-round` be aware that it is at the expense of performance. Traditional methods of rounding that use the `Math` class are much faster but at the expense of accuracy. You need to decide what's more important for your use-case.\n\n## Contributing\n\nGot an issue or a feature request? [Log it](https://github.com/codeandcats/reliable-round/issues).\n\n[Pull-requests](https://github.com/codeandcats/reliable-round/pulls) are also welcome. 😸\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeandcats%2Freliable-round","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeandcats%2Freliable-round","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeandcats%2Freliable-round/lists"}