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

155
Views
analizar decimale toFixed(2) en decimales que no son 0

El objetivo es tener 2 decimales sin contar el 0

1,2234 => 1,22

0,2345 => 0,23

0,02345 => 0,023 (en lugar de 0,02)

0.0000002345 => 0.00000023 (en lugar de 0)

0.0000002346545645645646465465 => 0.00000023 (en lugar de 0)

0.002035 => 0.002 en lugar de 0)

Quiero analizar toFixed(2) pero en los decimales que no son 0. ¿Cómo hacerlo correctamente?

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

0

Creo, por ejemplo, lo que quiso decir eliminar los últimos 2 dígitos en lugar de fijarlos en 2 decimales.

Para hacerlo, heres mi enfoque.

 function removeLastDigit(number, amount = 2) { const numberString = number.toString(); if(numberString.indexOf('.') === -1) return number; let numberLength = numberString.length; for(; numberLength >= 0 && amount; numberLength--){ if (numberString[numberLength] !== '0') amount--; } return +numberString.slice(0, numberLength); } let num = 0.003040; console.log(removeLastDigit(num)) //0.03
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!