How do I calculate a input
(integer value) and a (real) currency variable in javascript ?
The result is 6.7 and not 6.70 (I have tried many examples here in 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>