I am trying this script to calculate and prit the result in a form input readonly. While this works fine i need the numbers to be shown like this: 2.000.000 instead of 2.000.000.00. I need those 2 zeros at the end gone. I googled it but all I find are sollutions with the comma intact. As this script is very basic and simple i hope that for my problem there is a very simple and basic sollution.
<script> getPrice = function() { var numVal1 = Number(document.getElementById("price").value); var numVal2 = Number(document.getElementById("discount").value) ; var totalValue = numVal1 * numVal2 document.getElementById("total").value = totalValue.toFixed(2).replace(/d(?=(d{3})+.)/g, '$&.'); } </script>
Have you tried this :
totalValue.toFixed(2).replace(/d(?=(d{3})+.)/g, '$&.').slice(0, -3)
1.4m articles
1.4m replys
5 comments
57.0k users