Decimal in indicator output

Hi there!
I found another way to handle this issue.
You should use regular input field instead of indicator.
For instance, you have to input fields with 2 decimal places and an input field which make sum these two input fields.Add this script into your HTML file of custom dataset and adjust it according to your needs (IDs of input fields);

function calculateSum_with_decimal_places() {
var inputFieldIDs = [
“ID1”,
“ID2”
];

                    var sum = 0;

                    for (var i = 0; i < inputFieldIDs.length; i++) {
                            var inputField = document.getElementById(inputFieldIDs[i]);
                            var inputValue = inputField.value === null || inputField.value === "" ? 0.00 : parseFloat(inputField.value);
                            sum += inputValue;
                    }

                    var roundedSum = sum.toFixed(2);

                    var outputField = document.getElementById("ID3");
                    outputField.value = roundedSum;

                    outputField.dispatchEvent(new Event("change"));
            }

            function bindInputFieldEvents() {
                    var inputFieldIDs = [
                            "ID1",
                            "ID2"
                    ];

                    for (var i = 0; i < inputFieldIDs.length; i++) {
                            var inputField = document.getElementById(inputFieldIDs[i]);
                            inputField.addEventListener("blur", calculateSum_with_decimal_places);
                    }
            }

            // Call the bindInputFieldEvents function to bind the lostfocus event to input fields
            bindInputFieldEvents();

Here the ID1 and ID2 are IDs of decimal input fields and ID3 is ID of input field that calculating sum of ID1 and ID2 values.
function calculateSum_with_decimal_places() - doing calculations
function bindInputFieldEvents() - launch function calculateSum_with_decimal_places() when blur event of ID1 and ID2 input fields is occured.

Hope this will be helpfull.

Warm regards,
Adil

1 Like