From 80857dd779c4d56caf4242ecdb16d36cdccf0d50 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Fri, 24 Mar 2023 13:58:55 +0800 Subject: [PATCH] fix: support input when it starts with a dot --- packages/widget/src/utils/format.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/widget/src/utils/format.ts b/packages/widget/src/utils/format.ts index baddbbe7e..7ffe10639 100644 --- a/packages/widget/src/utils/format.ts +++ b/packages/widget/src/utils/format.ts @@ -68,7 +68,10 @@ export const formatAmount = ( if (!amount) { return amount; } - const formattedAmount = amount.replaceAll(',', '.'); + let formattedAmount = amount.replaceAll(',', '.'); + if (formattedAmount.startsWith('.')) { + formattedAmount = '0' + formattedAmount; + } const parsedAmount = parseFloat(formattedAmount); if (isNaN(Number(formattedAmount)) && !isNaN(parsedAmount)) { return parsedAmount.toString();