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

295
Vistas
Calculation, replace dot with a comma

I have an order form on which I use the jQuery Calculation Plugin to sum up the total.

This summing up works fine, yet there is a problem with the produced 'sum'. In the sum I wish to replace any dot with a comma.

The basis of the code is;

function ($this) {
    var sum = $this.sum();
    $("#totaal").html("€ " + sum2);
}

Using a .replace() directly on the var sum doesn't work (referenced function not available on object). I have also tried this (but without effect);

var sum2 = sum.toString().replace(',', '.');

As I'm kind of new to jQuery I'm pretty much stuck now, could anyone point me in the right direction?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Your replace line is almost right. You need to use a regexp with the g option, which says to replace all instances instead of just the first. You also have the order swapped (first is what to find, second is what to replace it with).

var sum2 = sum.toString().replace(/\./g, ',');

Note the \ before the .: . has a special meaning in a RegExp, so it has to be escaped.

over 4 years ago · Santiago Trujillo Denunciar

0

If Sum was a number then this would work.

var sum_formatted = String( sum ).replace(/\./g,',');

Can you run typeof(sum) and tell us what the output is.

Also if you can set the project up in jsfiddle.com that would be great.

over 4 years ago · Santiago Trujillo Denunciar

0

Your problem is that your replace function should read replace('.', ',') not the other way around (you had replace(',', '.')), Note that the first argument is what you're looking for, and the second argument is what you want there instead. You were replacing all commas with periods. Regex here is unnecessary.

over 4 years ago · Santiago Trujillo 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