Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Display INR number only if it's a number with more than 3 digits

JSFiddle DEMO: https://jsfiddle.net/bukh7jwL/

I have a table with text & numbers and facing 2 problems.

  1. It disables all the text values and displays it as ₹NaN!!
  2. I would like to avoid applying the JS if the number has less than 100 as value or 3 digits.

How do I go about doing this?

HTML:

<center>
    <p>
      <table>
        <tr><td>This is amazing</td></tr>
        <tr><td>92834</td></tr>
        <tr><td>33</td></tr>
        <tr><td>What?</td></tr>
      </table>
</center>

JS:

$('td').each(function() {
  var monetary_value = $(this).text();
  var i = new Intl.NumberFormat('en-IN', {
    style: 'currency',
    currency: 'INR'
  }).format(monetary_value);
  $(this).text(i);
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I've added the following statement to your code to check if we want to run the NumberFormat.

$.isNumeric(monetary_value) && (monetary_value < 100 || monetary_value.length == 3)

$.isNumeric(monetary_value) checks if it's a number.

(monetary_value < 100 || monetary_value.length == 3) checks if the value is below 100 or the length is 3 characters long.

$('td').each(function() {
  var monetary_value = $(this).text();
  if ($.isNumeric(monetary_value) && (monetary_value < 100 || monetary_value.length == 3)) {
    var i = new Intl.NumberFormat('en-IN', {
      style: 'currency',
      currency: 'INR'
    }).format(monetary_value);
  }
  $(this).text(i);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<center>
    <p>
      <table>
        <tr><td>This is amazing</td></tr>
        <tr><td>92834</td></tr>
        <tr><td>33</td></tr>
        <tr><td>What?</td></tr>
      </table>
</center>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to first check if the string is a number or not after that you need to check if the number digits are 3 or more. After that using toLocaleString() the number will be converted into INR currency

function isNumeric(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

$('td').each(function() {
  var monetary_value = $(this).text();
  if(isNumeric(monetary_value)) {
    let moneyVal = parseFloat(monetary_value);
    if( (moneyVal < 100 || moneyVal.toString().length == 3) ){
    var i = moneyVal.toLocaleString('en-IN', {
    maximumFractionDigits: 2,
    style: 'currency',
    currency: 'INR'
});
    $(this).text(i);
    
    }
  }
});
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<center>
    <p>
      <table>
        <tr><td>This is amazing</td></tr>
        <tr><td>92834</td></tr>
        <tr><td>33</td></tr>
        <tr><td>What?</td></tr>
      </table>
</center>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda