Search code examples
javascriptreplacewebflow

How to replace dot with a comma in the number


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


Solution

  • You can use

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