0
I have a problem that at first, is silly, but I am not able to solve, I have this function in ajax
, that takes the values of input
, and sends it to the controler
:
var url = "/PedidoFornecedor/Adicionar1";
var ProdutoPedidoID = $idprodutopedido;
var ProdutoID = $("#produtoid").val();
var CodigoProduto = $("#idproduto").val();
var Qtd = $("#qtd").val();
var QtdFalta = $("#qtd").val();
var PrecoCusto = $("#precocusto").val();
var DescontoV = $("#descontov").val();
var DescontoP = $("#descontop").val();
var ICMS = $("#icms").val();
var AliquotaICMS = $("#aliquotaicms").html().replace("%", "");
var IPI = $("#ipi").val();
var ISS = $("#iss").val();
var PedidoID = $("#pedidoid").val();
var DataEntrega = $("#dataentrega").val();
var DescricaoProduto = $("#descricaoproduto").html();
var Total = (parseFloat(Qtd) * parseFloat(PrecoCusto.replace(/\./g, '').replace(',', '.'))) - parseFloat(DescontoV.replace(/\./g, '').replace(',', '.'));
var vICMS = (parseFloat(Total) * (parseFloat(AliquotaICMS.replace(/\./g, '').replace(',', '.')) / 100));
var vISS = (parseFloat(Total) * (parseFloat(ISS.replace(/\./g, '').replace(',', '.')) / 100));
var vIPI = (parseFloat(Total) * (parseFloat(IPI.replace(/\./g, '').replace(',', '.')) / 100));
$.ajax({
url: url,
data: {
produtoPedidoID: ProdutoPedidoID, produtoID: ProdutoID, codigoProduto: CodigoProduto, qtd: Qtd, qtdFalta: QtdFalta, precoCusto: PrecoCusto,
descontoV: DescontoV, descontoP: DescontoP, icms: ICMS, aliquotaICMS: AliquotaICMS,
ipi: IPI, iss: ISS, dataEntrega: DataEntrega, pedidoID: PedidoID, descricaoProduto: DescricaoProduto,
total: Total, vicms: vICMS, viss: vISS, vipi: vIPI
},
datatype: "json",
type: "POST",
success: function (data) {
And here is the code to receive on controller
:
public ActionResult Adicionar1(int? produtoPedidoID, int produtoID, string codigoProduto, int qtd, int qtdFalta, float precoCusto, float descontoP,
float descontoV, int icms, float aliquotaICMS, float ipi, float iss, DateTime? dataEntrega,
int pedidoID, string descricaoProduto, float total, float vicms, float viss, float vipi)
{
In these variables, however, it never works, every time I try gives problem in some number, if I send 1000,50 it saves 100050, or if I send 5,202,00 it receives without being format, always with problems in any of the types. or the problem in the pennies, or in the tens, I’ve tried several ways, either it works one or it works the other kind, no way I tried it worked 100%. I know it’s silly, I’d like to better understand what’s going on in these conversion problems. I have also tried in the controller receive string type, and also always gives some problem.
EXAMPLE
Thus, in the debugger
the total amount being sent by ajax
is 5300.2
, and in the controller
he’s getting 53002
and it would be right to receive 5300,20
EDIT I tried that way below and it didn’t work either:
var Total = Number(parseFloat(Qtd) * Number(parseFloat(PrecoCusto.replace(/\./g, '').replace(',', '.')))) - Number(parseFloat(DescontoV.replace(/\./g, '').replace(',', '.')));
var vICMS = Number(parseFloat(Total) * Number(parseFloat(AliquotaICMS.replace(/\./g, '').replace(',', '.')) / 100));
var vISS = Number(parseFloat(Total) * Number(parseFloat(ISS.replace(/\./g, '').replace(',', '.')) / 100));
var vIPI = Number(parseFloat(Total) * Number(parseFloat(IPI.replace(/\./g, '').replace(',', '.')) / 100));
Are you using the comma to separate the whole part from the fractionated part? Check who is the decimal point in the two languages you are working on, Javascript usually ignores the location information and uses "." (dot) but I don’t know if in the language of controller (C#? ) is the same.
– Giovanni Nunes
Have you tried using maskMoney? We did an implementation very similar to yours, we used maskMoney for decimal problems.
– Adriano Praia
@Adrianopraia never used, has some example to assist ?
– Mariana
Here in the repository is an example of how to use maskMoney, any questions available. https://github.com/plentz/jquery-maskmoney
– Adriano Praia