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

146
Vistas
Is there a way to add a number in a number separated by commas using regex in Jquery?

I want to add a specific number to a number in HTML div separated with commas, another variation of this Is there any way to add number separated in html using regex and jquery?

Here is my trial code:

<div id="u-g-wb-break-word">150,452,032.32</div>
<div id="u-g-wb-break-word">455,666.67</div>
<div id="u-g-wb-break-word">977,435,787.992</div>
var a=$('#u-g-wb-break-word').text();
a=a.replace(/\,/g,'');
a=parseInt(a,10) + 17000;
console.log(a);
$('#u-g-wb-break-word').text(function(i, s) {
  return numberWithCommas(s.replace(/^[0-9,]*/g, a));
});

function numberWithCommas(x) {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

I am getting my desired output but only for the first div with one number.

the output of the above code is -

150,469,032.32
455,666.67
977,435,787.992

But I want to add it to every number. Is there any way to perform it in one regex? As mentioned in the above question link. If not what is the best way to do it. Thanks in Advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is better to use class, not id, as id must be unique within document:

$('.u-g-wb-break-word').text((i, s) => new Intl.NumberFormat().format(parseFloat(s.replaceAll(',',''))+1700));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="u-g-wb-break-word">150,452,032.32</div>
<div class="u-g-wb-break-word">455,666.67</div>
<div class="u-g-wb-break-word">977,435,787.992</div>

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