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

250
Views
How to convert a floating number to fixed floating number using JavaScript

For example, I want to calculate 3/6. 3/6 answer is a 0.5 floating number. When I fixed this number with the javascript toFixed(6) method it returned '0.500000'. The problem is that '0.500000' is a string. But I want a floating number with 6 digits after the dot(.). How can I do that? I tried this but it's won't work.

parseFloat((3/6).toFixed(6))
//output = 0.5 but i want 0.500000
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Well,

parseFloat((3/6).toFixed(6))
//output = 0.5 means everything after .5 is 0

If you print it to the console it will remove the unnecessary zero. When you need to print up to 5 or 10 decimal points, you have to convert the number into a string using the toFixed method.

about 4 years ago · Juan Pablo Isaza Report

0

Why are you using toFixed inside the parseFloat() because of that it is returning you 0.5

Do this

let a = parseFloat((3/6).toFixed(6))
console.log(a)
about 4 years ago · Juan Pablo Isaza Report

0

I updated my answer. I did not get that you wanted to use the output as a number. I don't think that what you want to achieve is possible. It's possible only if you keep you value as a string.

const numb = 3/6;
console.log(numb.toFixed(6));

For documentation: https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

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!