I’m currently using Blaze and the Collection2 module for schemas.
I’m working on an application that has a lot of prices, and with the schema being number + decimal, it seems to be rounding off the numbers. For example, $5.10 becomes $5.1.
Any advice on how I could properly force 2 decimal places with either Blaze or my collection?
Thanks!
I know of two options. you can either store it as a string '5.10'
and then parse it with parseFloat(value)
on the client, but then you can’t do any type of query or analysis that relies on it being a number so I wouldn’t do that. The other option is you can just store it as is because it’s really the correct way to store that number, and on the client when you display it use a filter to convert it from 5.1
to 5.10
with num.toFixed(2)
, which actually converts it to a string and adds the '0'
1 Like