I'd like to display numerical information to users in a flexible way. toFixed and toPrecision always pad with zeros, which is undesirable. Ideally, I would be able to express that:
- 5.450000000001 should be displayed as "5.45"
- 6.0 should be displayed as "6"
- 5.45001 should be displayed as "5.45001", but I'd also like to explicitly say "use no more than 2 decimal places", in which case this should be displayed as "5.45".
Are there good JS libraries for displaying numbers this way? If not, is there a good library in some other language that I can translate?
0. If it ends in a0you want the remove the trailing0. Right?