0

Example

65.110 //result = 65.11
65.111 //result = 65.111
65.100 //result = 65.10
65.000 //result = 65.00

i tried the below one but it's not working

 round(3).replace(/(\.0+|0+)$/, '');
  • 1
    Does this answer your question? [Remove insignificant trailing zeros from a number?](https://stackoverflow.com/questions/3612744/remove-insignificant-trailing-zeros-from-a-number) – rosmak Feb 18 '22 at 09:21

1 Answers1

1

You could just replace the last zero, if exist.

const
    format = number => number.toFixed(3).replace(/0$/, '');

console.log([65.110, 65.111, 65.100, 65.000].map(format));
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392