{"id":15755104,"url":"https://github.com/triplespeeder/bn2string","last_synced_at":"2026-01-19T22:31:51.935Z","repository":{"id":51698450,"uuid":"215501680","full_name":"TripleSpeeder/bn2string","owner":"TripleSpeeder","description":"Provide ready-to-use display strings for BN.js instances.","archived":false,"fork":false,"pushed_at":"2022-12-30T18:52:34.000Z","size":29,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-24T23:20:46.625Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TripleSpeeder.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-10-16T08:52:45.000Z","updated_at":"2020-06-02T17:23:38.000Z","dependencies_parsed_at":"2023-01-31T13:30:36.583Z","dependency_job_id":null,"html_url":"https://github.com/TripleSpeeder/bn2string","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TripleSpeeder%2Fbn2string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TripleSpeeder%2Fbn2string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TripleSpeeder%2Fbn2string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TripleSpeeder%2Fbn2string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TripleSpeeder","download_url":"https://codeload.github.com/TripleSpeeder/bn2string/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247623007,"owners_count":20968574,"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":[],"created_at":"2024-10-04T08:07:24.722Z","updated_at":"2026-01-19T22:31:51.899Z","avatar_url":"https://github.com/TripleSpeeder.png","language":"JavaScript","readme":"# bn2string\nProvide ready-to-use display strings for BN.js instances.\n\n## Installation\n```bash\nnpm install @triplespeeder/bn2string\n```\n\n## Usage\nAssume we have a balance of around 12500 Tether (USDT) tokens. USDT is specified with 6 decimals.\nFor display in a GUI we want to have the human-readable USDT value, both rounded to 2 decimals and in full precision.\n\n```javascript\nvar BN = require('bn.js')\nvar bn2DisplayString = require('@triplespeeder/bn2string')\n\nconst value = new BN('12525652700')\nconst decimals = new BN('6')\nconst roundToDecimals = new BN('2')\n\nvar {precise, rounded} = bn2DisplayString({value, decimals, roundToDecimals})\n\nconsole.log(\"Precise balance: \" + precise + \" USDT\")\nconsole.log(\"Rounded balance: \" + rounded + \" USDT\")\n```\n\nOutput:\n```bash\n[michael]$ node example.js\nPrecise balance: 12 525.652700 USDT\nRounded balance: 12 525.65 USDT\n```\n\n### Changing the decimal separator\nBy default '.' is used as decimal separator. This can be changed by providing a different symbol, e.g.\n```javascript\nvar {precise, rounded} = bn2DisplayString({value, decimals, roundToDecimals, decimalSeparator:','})\n```\nOutput:\n```bash\n[michael]$ node example.js\nPrecise balance: 12 525,652700 USDT\nRounded balance: 12 525,65 USDT\n```\n\n### Changing digit grouping\nBy default the integer digits are grouped as triplets and separated by unicode symbol ```u202F```, the \"narrow no-break space\" (See https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping for reasoning). This can be changed with the optional parameter 'groupSeparator':\n```javascript\nvar {precise, rounded} = bn2DisplayString({value, decimals, roundToDecimals, groupSeparator: ','})\n```\nOutput:\n```bash\n[michael]$ node example.js\nPrecise balance: 12,525.652700 USDT\nRounded balance: 12,525.65 USDT\n\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriplespeeder%2Fbn2string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftriplespeeder%2Fbn2string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriplespeeder%2Fbn2string/lists"}