From 2da9f890ea341654a97bb5db68e1734b23bdff55 Mon Sep 17 00:00:00 2001 From: Tulika-eGov Date: Tue, 19 Nov 2024 12:15:34 +0530 Subject: [PATCH] UCEM-1030 : updated the multiplication logic to handle decimal values using string methodology --- .../micro-ui-internals/example/package.json | 2 +- .../packages/modules/Measurement/package.json | 2 +- .../Measurement/src/utils/view_utilization.js | 32 +++++++++++++------ frontend/micro-ui/web/package.json | 2 +- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/frontend/micro-ui/web/micro-ui-internals/example/package.json b/frontend/micro-ui/web/micro-ui-internals/example/package.json index 36937fc203..bb6d361baa 100644 --- a/frontend/micro-ui/web/micro-ui-internals/example/package.json +++ b/frontend/micro-ui/web/micro-ui-internals/example/package.json @@ -17,7 +17,7 @@ "@egovernments/digit-ui-module-dss": "1.5.52", "@egovernments/digit-ui-module-attendencemgmt": "0.4.15", "@egovernments/digit-ui-module-contracts": "0.4.15", - "@egovernments/digit-ui-module-measurement":"0.2.18", + "@egovernments/digit-ui-module-measurement":"0.2.19", "@egovernments/digit-ui-module-estimate": "0.4.22", "@egovernments/digit-ui-module-masters": "0.4.23", "@egovernments/digit-ui-module-project": "0.4.17", diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/Measurement/package.json b/frontend/micro-ui/web/micro-ui-internals/packages/modules/Measurement/package.json index b1f36a6fc0..1dbc273e83 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/Measurement/package.json +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/Measurement/package.json @@ -1,6 +1,6 @@ { "name": "@egovernments/digit-ui-module-measurement", - "version": "0.2.18", + "version": "0.2.19", "description": "Measurement Module UI", "main": "dist/index.js", "module": "dist/index.modern.js", diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/Measurement/src/utils/view_utilization.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/Measurement/src/utils/view_utilization.js index c5f5f688ed..9a5464f3b1 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/Measurement/src/utils/view_utilization.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/Measurement/src/utils/view_utilization.js @@ -26,24 +26,38 @@ var multiply = function(num1, num2) { }; const multiplyWithDecimals = (v1, v2) => { - const getDecimalPlaces = num => (num.includes('.') ? num.split('.')[1].length : 0); - + const getDecimalPlaces = num => { + return num.includes('.') ? num.split('.')[1].length : 0; + }; + const d1 = getDecimalPlaces(v1); const d2 = getDecimalPlaces(v2); - + // Remove decimals from both numbers const num1 = v1.replace('.', ''); const num2 = v2.replace('.', ''); - + // Multiply as whole numbers - let result = multiply(num1, num2); - + const result = (BigInt(num1) * BigInt(num2)).toString(); // Use BigInt for accurate multiplication + // Insert decimal point at the correct place const totalDecimals = d1 + d2; if (totalDecimals > 0) { - const pointPos = result.length - totalDecimals; - result = result.padStart(totalDecimals + 1, '0'); // Ensure result has enough length - result = result.slice(0, pointPos) + '.' + result.slice(pointPos); + const resultLength = result.length; + const pointPos = resultLength - totalDecimals; + + // Handle cases where result length is shorter than decimal places + const paddedResult = result.padStart(totalDecimals, '0'); // Ensure enough digits for decimals + const integerPart = paddedResult.slice(0, pointPos > 0 ? pointPos : 0); + const fractionalPart = paddedResult.slice(pointPos > 0 ? pointPos : 0); + + // Combine integer and fractional parts + let formattedResult = (integerPart || '0') + (fractionalPart ? '.' + fractionalPart : ''); + + // Remove unnecessary leading and trailing zeros + formattedResult = parseFloat(formattedResult).toString(); + + return formattedResult; } return result; diff --git a/frontend/micro-ui/web/package.json b/frontend/micro-ui/web/package.json index 93679c37c3..8d090fa2bd 100644 --- a/frontend/micro-ui/web/package.json +++ b/frontend/micro-ui/web/package.json @@ -24,7 +24,7 @@ "@egovernments/digit-ui-module-dss": "1.5.52", "@egovernments/digit-ui-module-attendencemgmt": "0.4.15", "@egovernments/digit-ui-module-contracts": "0.4.15", - "@egovernments/digit-ui-module-measurement":"0.2.18", + "@egovernments/digit-ui-module-measurement":"0.2.19", "@egovernments/digit-ui-module-estimate": "0.4.22", "@egovernments/digit-ui-module-masters": "0.4.23", "@egovernments/digit-ui-module-project": "0.4.17",