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

128
Views
Ocultar siempre el número decimal .00

Me gustaría formatear mis números decimales para mostrar 2 lugares decimales, pero .00 siempre se ocultará.

ejemplo

 value expect return ------ ------- ------ 1.00 1 1.00 1 1 1.00 1.6 1.60 1.60 1.451 1.45 1.45



Mi código

 Vue.filter("currency", value => { return parseFloat(value).toFixed(2); });
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Retire .00 del final si existe:

 return parseFloat(value).toFixed(2).replace(/\.00$/, '')
about 4 years ago · Juan Pablo Isaza Report

0

Simplemente puede poner toFixed EN parseFloat de esta manera:

 Vue.filter("currency", value => { return parseFloat(value.toFixed(2)) });

toFixed redondeará/rellenará el número a una longitud específica, pero también lo convertirá en una cadena. Convertir eso de nuevo a un tipo numérico no solo hará que el número sea más seguro de usar aritméticamente, sino que también eliminará automáticamente cualquier 0 final.

Referencia: https://newbedev.com/remove-insignificant-trailing-zeros-from-a-number

Actualizar

Esta solución no considera el caso: 1.6 -> 1.60 (verifique jsfiddle en el comentario)

about 4 years ago · Juan Pablo Isaza Report

0

Simplemente verifique si el número es un número entero al verificar el recordatorio en la división con 1

 Vue.filter("currency", value => { return parseFloat(value) % 1 === 0 ? parseFloat(value).toString() : parseFloat(value).toFixed(2); });

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!