5
How do I calculate a input
(integer value) and a variable in (real) currency in javascript?
The result is being 6.7 and not 6.70 (I have tried many examples here of the forum, but nothing yet).
function Calcular() {
var valor1 = 3.35;
var teste = Number(document.getElementById("teste").value);
var result = document.getElementById("Resultado");
if (result.textContent === undefined) {
result.textContent = String(teste * valor1);
} else { // IE
result.innerText = String(teste * valor1);
}
}
<input type="text" id="teste" name="teste" onkeyup="Calcular();" value="2">
<div id="Resultado"></div>