{"id":26180044,"url":"https://github.com/jellydn/ethers-bignumber-demo","last_synced_at":"2026-04-22T01:32:30.888Z","repository":{"id":188062439,"uuid":"606279863","full_name":"jellydn/ethers-bignumber-demo","owner":"jellydn","description":"How to convert to BigNumber's ethers.js without error.","archived":false,"fork":false,"pushed_at":"2023-12-15T14:41:05.000Z","size":10,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-11T21:54:15.379Z","etag":null,"topics":["bignumber","ethersjs","web3"],"latest_commit_sha":null,"homepage":"https://dash.deno.com/playground/ether-big-number","language":"TypeScript","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/jellydn.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}},"created_at":"2023-02-25T02:44:07.000Z","updated_at":"2023-11-21T07:05:44.000Z","dependencies_parsed_at":"2023-08-13T15:50:48.570Z","dependency_job_id":null,"html_url":"https://github.com/jellydn/ethers-bignumber-demo","commit_stats":null,"previous_names":["jellydn/ethers-bignumber-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jellydn/ethers-bignumber-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fethers-bignumber-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fethers-bignumber-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fethers-bignumber-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fethers-bignumber-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jellydn","download_url":"https://codeload.github.com/jellydn/ethers-bignumber-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jellydn%2Fethers-bignumber-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32117346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T00:31:26.853Z","status":"ssl_error","status_checked_at":"2026-04-22T00:30:22.894Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["bignumber","ethersjs","web3"],"created_at":"2025-03-11T21:54:18.987Z","updated_at":"2026-04-22T01:32:30.873Z","avatar_url":"https://github.com/jellydn.png","language":"TypeScript","funding_links":["https://ko-fi.com/Q5Q61Q7YM"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eWelcome to ethers-bignumber-demo 👋\u003c/h1\u003e\n\u003cp\u003e\n How to convert to BigNumber's ethers.js without error.\n\u003c/p\u003e\n\n[![IT Man - Tech #34 - How to use BigNumber's ethers.js like PRO [Vietnamese]](https://i.ytimg.com/vi/uzE813GIeY4/hqdefault.jpg)](https://www.youtube.com/watch?v=uzE813GIeY4)\n\n## Motivation\n\nYou might have these kind of errors when use `BigNumber.from()` function.\n\n```typescript\nBigNumber.from(1.23);\n```\n\n```bash\nError: underflow [ See: https://links.ethers.org/v5-errors-NUMERIC_FAULT-underflow ] (fault=\"underflow\", operation=\"BigNumber.from\", value=1.23, code=NUMERIC_FAULT, version=bignumber/5.7.0)\n```\n\nor\n\n```typescript\nBigNumber.from(Number.MAX_SAFE_INTEGER);\n```\n\n```bash\nError: overflow [ See: https://links.ethers.org/v5-errors-NUMERIC_FAULT-overflow ] (fault=\"overflow\", operation=\"BigNumber.from\", value=9007199254740991, code=NUMERIC_FAULT, version=bignumber/5.7.0)\n```\n\n## Solution\n\n```typescript\nimport { formatUnits, parseUnits } from \"npm:@ethersproject/units\";\nimport { BigNumber, BigNumberish } from \"npm:@ethersproject/bignumber\";\n\nexport function convertToCurrencyBigNumber(val: string | number): BigNumber {\n  return parseUnits(Number(val).toFixed(2), 2);\n}\n\nexport function convertFromCurrencyBigNumber(val: BigNumberish): string {\n  return formatUnits(val, 2);\n}\n```\n\n## Usage\n\n```typescript\nconvertToCurrencyBigNumber(300.59999999999997); //  BigNumber { _hex: \"0x756c\", _isBigNumber: true }\n\nconvertFromCurrencyBigNumber(convertToCurrencyBigNumber(300.59999999999997)); //  300.6\n```\n\n## Develop\n\nYou need to install [deno](https://deno.land/manual@v1.31.0/getting_started/installation) before run below command.\n\n```sh\ndeno task dev\n```\n\n## Test\n\n```sh\ndeno test\n```\n\n## Reference\n\n- [How to pass unsafe numbers into BigNumber? · Issue #452 · ethers-io/ethers.js](https://github.com/ethers-io/ethers.js/issues/452)\n\n## Author\n\n👤 **Huynh Duc Dung**\n\n- Website: https://productsway.com/\n- Twitter: [@jellydn](https://twitter.com/jellydn)\n- Github: [@jellydn](https://github.com/jellydn)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Q5Q61Q7YM)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjellydn%2Fethers-bignumber-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjellydn%2Fethers-bignumber-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjellydn%2Fethers-bignumber-demo/lists"}