2
I’m having trouble using toFixed
in a return json
.
A part of the code
success: function (dados){
$.each(dados, function(index){
var guidPedido = dados[index].guid;
var statusPedido = dados[index].status;
var nomePedido = dados[index].nome;
var enderecoPedido = dados[index].endereco;
var totalPedido = dados[index].total;
var dataPedido = dados[index].data;
var telefonePedido = dados[index].telefone;
var numerocasaPedido = dados[index].numero;
var formaPagamento = dados[index].formaPagamento;
var observacaoPedido = dados[index].observacao;
var cpfClientePedido = dados[index].cpf;
var entregarPedido = dados[index].entregar;
var tokenPedido = dados[index].token;
var bairroPedido = dados[index].bairro;
var pagamentotext = 0;
if (statusPedido == 1) {
var statuspedidotext = "Processando";
}
if (formaPagamento == 0) {
pagamentotext = "Dinheiro";
} else {
pagamentotext = "Cartão/Crédito/Débito";
}
totalPedido = totalPedido.toFixed(2);
The mistake is:
ERROR: lanc_pedidos.php:112 Uncaught Typeerror: Cannot read Property 'toFixed' of null
After withdrawing the possibility of dados[index].total
was null
, get the following error:
Typeerror: totalPedido.toFixed is not a Function
Can someone explain to me what’s wrong ?
That mistake means that
dados[index].total
isnull
. This value may benull
? if "yes" you want to convertnull
to zero? case "no" you have an error somewhere else you need to fix first– Sergio
right now presents this Typeerror: totalPedido.toFixed is not a Function
– Jefferson Mello Olynyki
Okay, what do you give
console.log(typeof dados[index].total, dados[index].total);
?– Sergio
I got Sérgio, as follows totalPedido = parseFloat(totalPedido). toFixed(2);
– Jefferson Mello Olynyki
Okay, you were getting a string then. Great. If you already solved it you can delete the question maybe... or answer.
– Sergio
thanks for the help Sérgio, I will respond and leave in case someone has the same problem
– Jefferson Mello Olynyki
If you’re going to answer, state in detail Type of the variable, and why the error appeared and what makes the
parseFloat
:)– Sergio