getumbrel / umbrel-dashboard

[Deprecated] Moved to https://github.com/getumbrel/umbrel/tree/master/packages/dashboard. Web-based dashboard to interact with your Umbrel.
https://github.com/getumbrel/umbrel/tree/master/packages/dashboard
Other
132 stars 69 forks source link

fix rounding in satsToUSD view #401

Open johnpc opened 2 years ago

johnpc commented 2 years ago

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