Home > OS >  How to replace dot with a comma in the number
How to replace dot with a comma in the number

Time:01-19

Hey dear Stackoverflow community, I have a JS code that calculates various values ​​based on an input value. It is output with a dot, but it should be displayed with a comma.

How can I customize the code for this?

<script>
var input = document.getElementById("invest_input-1");
input.oninput = function() {

var out = ((input.value * 0.38));
document.getElementById('invest_output_result-1').innerHTML = out.toFixed(2);
var out = ((input.value * 0.032));
document.getElementById('invest_output_result-2').innerHTML = out.toFixed(2);
var out = ((input.value * 0.03));
document.getElementById('invest_output_result-3').innerHTML = out.toFixed(2);
var out = ((input.value * 0.13));
document.getElementById('invest_output_result-4').innerHTML = out.toFixed(2);
      
};
</script>

Thank you so much! Kind regards, Fabian

CodePudding user response:

You can use

out.toFixed(2).replace('.', ',');

CodePudding user response:

Based on the user's locale:

new Intl.NumberFormat().format(3500)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat#basic_usage

  • Related