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

199
Views
How to make a number from string with comma separators in JavaScript ("23,21" ---> 23,21)

Does anyone know how to make a number from a string with comma separators, in JS. I got: "23,21" and I want to get it as a number value.

"23,21" --> 23,21

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat

But before you need to replace comma for dot.

parseFloat('23,21'.replace(/,/, '.')); // == 23.21

let x = '16,5';
parseFloat(x.replace(/,/, '.')); // == 16.5
about 4 years ago · Juan Pablo Isaza Report

0

You can but not with the "comma" (,). In some countries people do use commas instead of dots to write decimals. If that's the case then what you can do is:

let a = "23,25";
let b = a.replaceAll(',', '.');
console.log(parseFloat(b));

But doing the this with the comma is also not wrong. But you will only get the part before the decimal.

i.e. 23 in your case

about 4 years ago · Juan Pablo Isaza Report

0

Check if you want this.

var str = '23,21';
console.log((str.split(",").map((i) => Number(i))));

UPDATE

 var str = '23,21';
 var arr = str.split(",").map((i) => Number(i));
 console.log(parseFloat(arr.join('.')));
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!