Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

fix rounding in satsToUSD view #401

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

johnpc
Copy link

@johnpc johnpc commented Jan 6, 2022

This pull request fixes an issue with the USD balance view on the dashboard.

Essentially, the rounding is done in a way where the USD value can round to a single decimal place, even though USD values are properly represented with two decimal places.

Screen Shot 2022-01-06 at 12 22 04 AM

This is essentially the logic that exists today:

"$" + Number(150.1.toFixed(2)).toLocaleString()

The problem with this is that casting to Number() removes the attempt at pinning the number of decimals via .toFixed().

The solution is to use Numbers native currency styling support:

Number("150.1").toLocaleString(Intl.NumberFormat().resolvedOptions().locale, {currency: 'usd', style: 'currency'})

Then it looks correct

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant