umbrel-dashboard icon indicating copy to clipboard operation
umbrel-dashboard copied to clipboard

fix rounding in satsToUSD view

Open johnpc opened this issue 4 years ago • 0 comments

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

johnpc avatar Jan 06 '22 05:01 johnpc