ae to com um problema criei uma function em java script para tranformar numeros interos em formato de dinhero mas ela nao retorna os centavos. alguem pode me ajudar?
[code] function calcularTroco(valorTotal){
var valor = document.getElementById(“tf_troco”).value;
var troco = valor - valorTotal;
var cents;
var trocod;
var x;
valor = valor.replace(",",".");
x = 0;
if(troco<0) {
troco = Math.abs(num);
x = 1;
}
if(isNaN(troco)) troco = "0";
cents = Math.floor((troco*100+0.5)%100);
troco = Math.floor((troco*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((troco.length-(1+i))/3); i++)
troco = troco.substring(0,troco.length-(4*i+3))+'.'
+troco.substring(troco.length-(4*i+3));
trocod = troco + ',' + cents;
if (x == 1) trocod = ' - ' + trocod;
var exibeTroco = " <font color='red'>Troco:R$ " + trocod + "</font>";
document.getElementById("labelTroco").innerHTML = exibeTroco;
}[/code]