0

For example, if I enter 5,000, the system recognizes as 5,00

Another problem that happens is that if I type, for example 5,100 the system recognizes as null and saves the value as 0.00

I tried everything to understand the problem, but I couldn't

How would I get fields to recognize values entered with commas or dots?

My code:

public class EstoqueDaEmbarcacao : Entity
{
    public decimal AguaCarregada { get; set; }

    public decimal DieselCarregado { get; set; }
}

jQuery

function fillInventoryData(barcoId) {
    $("#estoque-barco-id").val(barcoId);
    $("#estoque-barco-nome").val($("#selectEmbarcacao option:selected").text());
    $("#modal-estoque").modal('show');
}
function saveInventory() {
    $("#message-estoque").removeClass("alert-danger");
    $("#message-estoque").removeClass("alert-warning");
    var barcoId = $("#estoque-barco-id").val();
    var agua = $("#estoque-barco-agua").val().replace(",", ".");
    var diesel = $("#estoque-barco-diesel").val().replace(",", ".");
    var data = JSON.stringify({ AguaCarregada: agua, DieselCarregado: diesel, BarcoId: barcoId });
    if (agua == "" || diesel == "") {
        $("#message-estoque").addClass("alert-warning");
        $("#message-estoque").html("Fill in all fields to continue");
        return;
    }
    $.ajax({
        url: "/InfoApontamento/AtualizarEstoqueBarco",
        type: "POST",
        dataType: "json",
        data: data,
        contentType: "application/json",
        success: function (result) {

            if (!result.Success) {

                $("#message-estoque").html(result.ErrorDatail);
                $("#message-estoque").addClass("alert-danger");
            }
            else if (!result.Data) {
                $("#message-estoque").html(result.Message);
                $("#message-estoque").addClass("alert-danger");
            }
            else {
                alert("Salvo com sucesso!");
                $("#modal-estoque").modal('hide');
                $('#estoque-barco-agua').val("");
                $('#estoque-barco-diesel').val("");
                // abrirModalManutencao();
                preInicializarModal();
            }
        }
    });

}

Page:

<div class="form-row">
                    <div class="col">
                        <label for="embarcacaoInput">Água</label>
                        <input type="number" step="0.01" class="form-control" id="estoque-barco-agua">
                    </div>
                    <div class="col">
                        <label for="embarcacaoInput">Diesel</label>
                        <input type="number" step="0.01" class="form-control" id="estoque-barco-diesel">
                    </div>
                </div>

1 Answer 1

1

Change this line:

var data = JSON.stringify({ AguaCarregada: agua, DieselCarregado: diesel, BarcoId: barcoId });

for this (parseFloat()):

var data = JSON.stringify({ AguaCarregada: parseFloat(agua), DieselCarregado: parseFloat(diesel), BarcoId: barcoId });
Sign up to request clarification or add additional context in comments.

1 Comment

Hernandez The problem continues, the system still ignores the number of 0's after the comma and also does not accept nonzero numbers after the comma.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.