standardize chart values to two decimals

This commit is contained in:
Henry Dollman
2024-09-03 16:49:12 -04:00
parent 202a506485
commit af4c05e692
14 changed files with 58 additions and 19 deletions

View File

@@ -239,6 +239,19 @@ export function toFixedFloat(num: number, digits: number) {
return parseFloat(num.toFixed(digits))
}
let twoDecimalFormatter: Intl.NumberFormat
/** Format number to two decimal places */
export function twoDecimalString(num: number) {
if (!twoDecimalFormatter) {
twoDecimalFormatter = new Intl.NumberFormat(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})
}
// Return a function that formats numbers using the saved formatter
return twoDecimalFormatter.format(num)
}
/** Get value from local storage */
function getStorageValue(key: string, defaultValue: any) {
const saved = localStorage?.getItem(key)