Receive integer value in field view

Asked

Viewed 27 times

0

Guys, I need some help from you.

In my system I created a modal with data viewing pulling from the database.

I need one of these data to display only the integer numbers, as an example in the photo.

If it’s 30, I need it to display 30, if this 265, I need it to display 265 only.

Someone can help me?

inserir a descrição da imagem aqui

Controller where I do the calculations and step to the JS

[HttpPost]
        public JsonResult MethodGetDetails(int centroId = 0)
        {
            var centro = _hospitalService.GetByCentroId(centroId);
            List<string> list = new List<string>();
            if (centro != null)
            {
                // Estoque A
                list.Add((centro.EstoqueA * 2).ToString("N1"));//3

                // Estoque B
                list.Add((centro.EstoqueB * 2).ToString("N1"));//6

                // Estoque C
                list.Add((centro.EstoqueC * 2).ToString("N1"));//9

                // Estoque D
                list.Add((centro.EstoqueD * 2).ToString("N1"));//12

                // Estoque E
                list.Add((centro.EstoqueE * 2).ToString("N1"));//15

                // Estoque F
                list.Add((centro.EstoqueF * 2).ToString("N1"));//18


                list.Add(centro.Nome);
            }

            return Json(list, JsonRequestBehavior.AllowGet);
        }

Javascript:

function MethodGetDetails(id) {
    console.log(id);
    $.ajax({
        method: 'POST',
        url: 'MethodGetDetails',
        data: { centroId: id },
        success: function (response) {
            console.log('success: ' + response);
            $('.modal.MethodGetDetailsModal').modal('show');
            $('#trAddTD').text('');
            $('#nomeCentro').html(id + ' - ' + response[18]);

            $('#trAddTD').html(
               '<div class="row">' +
               '    <div class="col-md-12">' +
               '        <div class="row" style="margin-top: 15px;">' +
               '            <div class="col-md-6" style="padding-left: 20px;">' +
               '                <label>A: </label>' +
               '                <span data-toggle="tooltip" data-placement="bottom" title=""><i class="fa fa-flask"></i> <label>' + response[2] + ' </label></span>        ' +
               '            </div>' +
               '            <div class="col-md-6">' +
               '                <label>D: </label>' +
               '                <span data-toggle="tooltip" data-placement="bottom" title=""><i class="fa fa-flask"></i> <label>' + response[5] + ' </label></span>        ' +
               '            </div>' +
               '        </div>' +
               '        <div class="row" style="margin-top: 15px;">' +
               '            <div class="col-md-6" style="padding-left: 20px;">' +
               '                <label>B: </label>' +
               '                <span data-toggle="tooltip" data-placement="bottom" title=""><i class="fa fa-flask"></i> <label>' + response[8] + ' </label></span>        ' +
               '            </div>' +
               '            <div class="col-md-6">' +
               '                <label>E: </label>' +
               '                <span data-toggle="tooltip" data-placement="bottom" title=""><i class="fa fa-flask"></i> <label>' + response[11] + ' </label></span>        ' +
               '            </div>' +
               '        </div>' +
               '        <div class="row" style="margin-top: 15px;">' +
               '            <div class="col-md-6" style="padding-left: 20px;">' +
               '                <label>C: </label>' +
               '                <span data-toggle="tooltip" data-placement="bottom" title=""><i class="fa fa-flask"></i> <label>' + response[14] + ' </label></span>        ' +
               '            </div>' +
               '            <div class="col-md-6">' +
               '                <label>F: </label>' +
               '                <span data-toggle="tooltip" data-placement="bottom" title=""><i class="fa fa-flask"></i> <label>' + response[17] + ' </label></span>        ' +
               '            </div>' +
               '        </div>' +
               '    </div>' +
               '</div>');


        }
    })
}

MODAL CSHTML:

<div class="modal fade MethodGetDetailsModal" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Estoque Atual</h4>
            </div>
            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th id="nomeCentro"></th>
                        </tr>
                    </thead>
                    <tbody id="trAddTD"></tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-warning btn-loading" data-dismiss="modal" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Carregando">Fechar</button>
            </div>
        </div>
    </div>
</div>
  • What kind of data a centro.Estoque* ? float, decimal, int... ?

  • this in double.

1 answer

0


Instead of formatting as "N1" in ToString use "F0", which makes it 0 numbers after the comma.

  • Thank you very much, I did not know this feature

Browser other questions tagged

You are not signed in. Login or sign up in order to post.