From 6e5cacd2da38c7c50468892b35634d373b5f9b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20V=C3=A4in?= Date: Sat, 20 Jan 2024 15:07:45 +0200 Subject: [PATCH] fix type issues and rounding --- pages/index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pages/index.js b/pages/index.js index 7fc59d0..13393b0 100644 --- a/pages/index.js +++ b/pages/index.js @@ -13,6 +13,7 @@ import max from "lodash/max"; import min from "lodash/min"; import replace from "lodash/replace"; import round from "lodash/round"; +import toNumber from "lodash/toNumber"; import TaxInfo from "components/tax-info"; import formatCurrency from "utils/currency"; @@ -75,7 +76,6 @@ const Index = () => { const grossSalary = useMemo(() => { let grossSalaryValue = null; - console.log(values.amount, values.amountType); if (values.amount > 0) { // Salary fund if (values.amountType === "total") { @@ -122,9 +122,12 @@ const Index = () => { }; // solve the equation - grossSalaryValue = bisectionMethodAdvanced(func, values.amount, values.amount, values.amount * 2); - console.log(grossSalaryValue); - return grossSalaryValue; + grossSalaryValue = bisectionMethodAdvanced( + func, + toNumber(values.amount), + toNumber(values.amount), + toNumber(values.amount * 2) + ); } // Always return a value rounded to two decimal places @@ -278,7 +281,8 @@ const Index = () => { // valueAsNumber: true, onChange: (e) => { if (e.target.value) { - setValue("amount", replace(replace(e.target.value, ",", "."), /[^0-9.,]/g, ""), { + const value = replace(replace(e.target.value, ",", "."), /[^0-9.,]/g, ""); + setValue("amount", toNumber(value), { shouldDirty: true, }); }