-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What about toDecimal? #6
Comments
I tried to extend the class in #7. You should check it out. |
I wasn't ready to trust the math calculation of this:
So, since I'm only converting to decimal in order to display data, I'm doing a string manipulation to avoid any possibility of conversion issues (I think I had one scenario where this had actually happened and $4.30 became $4.31, so I decided to stick with string operations)
Just FYI if it's helpful for you. I have no idea which is better performance. My code hasn't been upgraded to work with #7 |
Even outside of performance considerations, your method the currency's Your implementation is definitely safe calculation-wise so I might use yours but I've failed to find an example where |
toFixed seems to be rounding to the closest decimal which I think is fine. If we really need to floor the value, we could use |
Now that I think about it, I think it was my backend API that was having the calculation failure and not Javascript... But even so I wanted to take the decimal_digits into account and this was the only way I could think of doing that, although this should work to use toFixed(2) and get the decimal in the right place.
|
Edit, missed the toFixed parameter change
|
Thanks for the help. I updated the |
#7 was merged and version |
Thanks @caccialdo, you're my hero! |
New changes are looking great btw. Thanks all |
I'm implementing this for the first time so perhaps this is something obvious but if I want to eventually output the money as a decimal is this not something which should live within the money object code?
Seems odd that you would safely be able to do calculations whilst it is represented as cents but then you risk causing an issue by having to do the toDecimal implementation yourself.
Thanks in advance for any advice
The text was updated successfully, but these errors were encountered: