My numbers are being saved and also displayed as attached image.
The numbers entered are not being separated by commas, like leaving for example the number 5000000, in format 5,000,000
How could I show for example the number 5000 in the format 5,000 instead of 5000,00
I know there are several topics dealing with this, but none of the solutions helped me.
I already tried this solution comma decimal seperator in asp.net mvc 5
And that: separate numbers by comma with asp.net mvc
My code:
public class stock
{
[Required(ErrorMessage = "Campo Obrigatório")]
[DisplayFormat(DataFormatString = "{0:0,0}")]
public decimal WaterLoad{ get; set; }
[Required(ErrorMessage = "Campo Obrigatório")]
[DisplayFormat(DataFormatString = "{0:0,0}")]
public decimal Diesel { get; set; }
}
function saveStock() {
$("#message-estoque").removeClass("alert-danger");
$("#message-estoque").removeClass("alert-warning");
var barcoId = $("#estoque-barco-id").val();
var water= $("#estoque-barco-agua").val().replace(",", ".");
var diesel = $("#estoque-barco-diesel").val().replace(",", ".");
var data = JSON.stringify({ AguaCarregada: agua, DieselCarregado: diesel, BarcoId: barcoId });
if (water == "" || diesel == "") {
$("#message-estoque").addClass("alert-warning");
$("#message-estoque").html("Preencha todos os campos para continuar");
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();
}
}
});
}