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

104
Vistas
Replace dot with comma Input while typing decimal points

I am using react hooks, and I want to achieve the following, replacing a dot with a comma while a using is typing in the Input text box. Below is my code :

const formatDecimal = (value: number) => Number(value).toLocaleString('de-DE');

  const onChange = useCallback(
    event => {
      const { value } = event.target;
      // @ts-ignore
      const newValue = formatDecimal(value)
      setFieldValue(name, newValue);
    },
    [setFieldValue, name],
  );

It doesn't work as expected, it only doesn't show the comma, whenever I type the dot.

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

0

You can use regex and String#replace function

const replaceDotWithComma = str => {
  return str.replace(/\./g, ',');
}

console.log(replaceDotWithComma('12.567'))
console.log(replaceDotWithComma('30.6'))

This is for the input field, you can do the reverse before saving the value as float.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The problem with different region the number display can changed .toLocaleString('de-DE') so The best case should use the library to do it

http://numeraljs.com/

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