From 175ce2be48d62b0bd6dad0f423bde3710a9c78cc Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Mon, 22 Jan 2024 11:09:01 -0700 Subject: [PATCH] added more helper methods. --- Views/Shared/_Layout.cshtml | 5 +++++ wwwroot/js/gasrecord.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 146d012..c31e772 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -65,6 +65,11 @@ input = input.replace(decimalSeparator, "."); return parseFloat(input); } + function globalFloatToString(input) { + var decimalSeparator = "@numberFormat.NumberDecimalSeparator"; + input = input.replace(".", decimalSeparator); + return input; + } @await RenderSectionAsync("Scripts", required: false) diff --git a/wwwroot/js/gasrecord.js b/wwwroot/js/gasrecord.js index e7621e1..90238bd 100644 --- a/wwwroot/js/gasrecord.js +++ b/wwwroot/js/gasrecord.js @@ -99,12 +99,12 @@ function getAndValidateGasRecordValues() { } if (gasCostType != undefined && gasCostType == 'unit') { var convertedGasCost = globalParseFloat(gasCost) * globalParseFloat(gasGallons); - gasCost = convertedGasCost.toFixed(2).toString(); - if (isNaN(gasCost)) + if (isNaN(convertedGasCost)) { hasError = true; $("#gasRecordCost").addClass("is-invalid"); } else { + gasCost = globalFloatToString(convertedGasCost.toFixed(2).toString()); $("#gasRecordCost").removeClass("is-invalid"); } }