Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!