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

218
Views
Integer price number to float Javascript

I am interacting with an API and it returns the price as in integer, for example:

99.59 is returned from the API like this: 9959

60.00 is returned like this 6000

252.90 is returned like this 25290

I'd love a function that takes in the integer number and turns it to float exactly like the above, so 25290 should be 252.90 and 9959 should be 99.59

Any help Is really appreciated.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use something like this.

const formatNumber = (value, precision = 2) => {
    return (value / 100).toFixed(precision);
}

console.log(formatNumber(60000, 3));
console.log(formatNumber(2529));

And use that formatNumber function for formatting.

Like, formatNumber(6000, 3) and it will return something like 60.000.

about 4 years ago · Santiago Trujillo Report

0

You could take a function and convert the value to a sting, maintain the length and add a dot.

const
    format = integer => integer
        .toString()
        .padStart(3, 0)
        .replace(/(?=..$)/, '.');

console.log(format(0));
console.log(format(9));
console.log(format(19));
console.log(format(9959));

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