Verificar se FLOAT é Negativo
Bom dia Amigos
Estou quebrando a cabeça, porem ainda nao cosegui nenhum exito.
tenho o codigo em
function numeroParaMoeda(n, c, d, t)
{
c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "" : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}
function moedaParaNumero(valor)
{
return isNaN(valor) == false ? parseFloat(valor) : parseFloat(valor.replace(".", "").replace(",", "."));
}
function SomaTD(valor) {
var vltotal ='1200,10';
var total = parseFloat(moedaParaNumero(valor)) - parseFloat(moedaParaNumero(vltotal));
// alert(total);
if (parseInt(total) < 0) {
$("#troco").val(numeroParaMoeda(0));
} else {
$("#troco").val(numeroParaMoeda(total));
}
console.log(total);
}
Onde na Função somaTD(valor) ...
verifica se o total é menor q zero.
Porem quero que se for < 0
ou seja NEGATIVO
ele retorne 0.
ele retorna -0,10(ex)
Alguem sabe como solucionar?
Aqui vcs podem ver em funcionamento
Discussão (3)
Carregando comentários...