0

aquí molestando de nuevo ahora vengo con otro detalle y es con el formato de numero en mi input con el tercer input que quiero formato de numero pero no me lo da como yo quiero, por ejemplo:

si meto en el primer input 11700 y el en segundo 10 me da 117,0 y quisiera que me lo arrojara así 1,170 como le hago para que me lo arroje así?? ya intente con un código que vi en otra parte de este maravillosa comunidad pero no le atino para que me de este formato que quiero en mi input 3.

function op1(){
    try{
        var v1 = parseInt(document.getElementById("v1").value.replace(/,/g, '')) || 0,
                v2 = parseInt(document.getElementById("v2").value) || 0;
                var num = parseInt(document.getElementById("v2").value.length);
                var mult= v1 * v2
                var txt= mult+""
                if (num >= 2) {
                    var texto = Intl.NumberFormat('es-419').format(txt);
                    document.getElementById("v3").value = texto.slice(0,5)
                }
                if (num <= 1) {
                    document.getElementById("v3").value = txt.slice(0,3)
                }

        //$("#descuentototal").html(tdes.toFixed(2));
    } catch(e) {}
}
<tr>
    <td class='text-right' colspan=3><B>Leucocito</B></td>
    <td class='text-right'><input type="text" id="v1" oninput="op1()" style="width:50px; font-weight:bold;"/></td>
</tr>

<tr>
    <td class='text-right' colspan=3><B>Monocito</B></td>
    <td class='text-right'><input type="text" id="v2" oninput="op1()" style="width:50px; font-weight:bold;"/></td>
</tr>

<tr>
    <td class='text-right' colspan=3><B>Monocito 2</B></td>
    <td class='text-right'><input type="text" id="v3" style="width:50px; font-weight:bold;"/></td>
</tr>

1 respuesta 1

0

Hola Alejandro si ya lo puse pero no me aparece como quiero ya que no me respeta el slice y me aparece toda la cantidad completa, en este caso si multiplicas 11700 y corto con slice y agarro 117 por 10 me da 1170 y me aparece asi 117,000 y yo quiero que me aparezca asi 1,170.

function op1(){
    try{
        var v1 = parseInt(document.getElementById("v1").value.replace(/,/g, '')) || 0,
                v2 = parseInt(document.getElementById("v2").value) || 0;
                var num = parseInt(document.getElementById("v2").value.length);
                var mult= v1 * v2
                var txt= mult+""
                if (num >= 2) {
                    var texto = Intl.NumberFormat('es-419').format(txt);
                    document.getElementById("v3").value = texto.slice(0.5)
                }
                if (num <= 1) {
                    document.getElementById("v3").value = txt.slice(0.3)
                }

        //$("#descuentototal").html(tdes.toFixed(2));
    } catch(e) {}
}
<tr>
    <td class='text-right' colspan=3><B>Leucocito</B></td>
    <td class='text-right'><input type="text" id="v1" oninput="op1()" style="width:50px; font-weight:bold;"/></td>
</tr>

<tr>
    <td class='text-right' colspan=3><B>Monocito</B></td>
    <td class='text-right'><input type="text" id="v2" oninput="op1()" style="width:50px; font-weight:bold;"/></td>
</tr>

<tr>
    <td class='text-right' colspan=3><B>Monocito 2</B></td>
    <td class='text-right'><input type="text" id="v3" style="width:50px; font-weight:bold;"/></td>
</tr>

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.