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

215
Views
Format number to always show how many 0's

I would like to format my numbers to display and replace how many 0's after three 0's

Examples:

number     display
------     -------
0.000001   0.0₅1
0.0000003  0.0₆3
0.001      0.001
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is an example how you can achieve this. I have commented the code. Feel free to modify the example yourself if you wish.

const convert = num => {
  const subs = [ '₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉' ]
  const [left, right] = num.toFixed(10).split('.') // break a number by the dot
  const result = right.match('^([0]{3,})') // for 000 and more zeroes
  if (result){
    const length = result[0].length; // get subs size
    return(left + '.0' + subs[length] + right.slice(length)) // join all parts
      .replace(/0+$/, '') // remove zeroes from the end
  } 
  return num // original
}

console.log([0.000001, 0.0000003, 0.001].map(convert)) 

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!