From d31714eccc37c3c71d3fd82dc49bbd68244fb8da Mon Sep 17 00:00:00 2001 From: Blue Falcon <93707274+blue-falcon-9001@users.noreply.github.com> Date: Tue, 23 Nov 2021 19:56:09 +0100 Subject: [PATCH] Rename parameter, respect fixed precision --- src/lib/utils.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/utils.js b/src/lib/utils.js index c3ce638..e0a403d 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -47,11 +47,15 @@ export function formatCurrency(_currencyLabel) { if (_currencyLabel.toLowerCase() == 'cap') return 'CAP'; return _currencyLabel; } -export function formatToDisplay(amount, maxPrecision, fixPrecision) { +export function formatToDisplay(amount, maxPrecision, isFixedPrecision) { if (amount == undefined || isNaN(amount)) return ''; if (!maxPrecision) maxPrecision = 100; - if (!fixPrecision && (amount*1 == 0 || amount * 1 >= 1) && (amount * 1).toFixed(3)*1 == Math.round(amount * 1)) return Math.round(amount).toLocaleString(); + if (isFixedPrecision) { + return (amount * 1).toFixed(maxPrecision); + } + + if ((amount*1 == 0 || amount * 1 >= 1) && (amount * 1).toFixed(3)*1 == Math.round(amount * 1)) return Math.round(amount).toLocaleString(); if (amount * 1 >= 1000 || amount * 1 <= -1000) { return Math.round(amount*1).toLocaleString();