Open kamov opened 5 years ago
The same issue, would be really useful to fix it.
+1 facing same issue Any Progress on this one? mid-2020 now and this one is still open...
https://twitter.com/taylorotwell/status/1256031217943818242
Also, if I remember correctly, this was a problem with DBAL, not Voyager directly.
I noticed the same problem with Laravel 7 and latest Voyager. I will take a look on how the table is created because I think it is just a matter of changing the input to allow the comma and for it to be interpreted in the table creating code. As of now, we need to manually update the decimal precision in the database itself, otherwise we can't store monetary values at all.
Monetary values shouldn't be stored in floating-point numbers anyway (https://spin.atomicobject.com/2014/08/14/currency-rounding-errors/. it's a bit old, but the points are still relevant)
Monetary values shouldn't be stored in floating-point numbers anyway (https://spin.atomicobject.com/2014/08/14/currency-rounding-errors/. it's a bit old, but the points are still relevant)
That is correct, but the decimal field is not a float. So it works
Yes, but what variable does that value go into when it gets pulled out of the database...?
Ah! I get it. Yes, the value will be treated as a float by internal conversion of PHP. But in the actual code you should never round the values, just format it. By the way that just reminded me I need to test saving the value with precision in the database, with the default input number of Voyager
Yes, but what variable does that value go into when it gets pulled out of the database...?
I have been thinking and maybe it is our approach that is wrong in this matter. How Voyager wants us to manage decimal or monetary values?
Yes, but what variable does that value go into when it gets pulled out of the database...?
I have been thinking and maybe it is our approach that is wrong in this matter. How Voyager wants us to manage decimal or monetary values?
For what is worth for monetary values I always try to avoid decimals, choose what's the precision and then use that as base. For example if your prices need cents use cents as unit, store the integer value and convert for display.
$ 3.14 stored as 314
@MrCrayon oh you are right! I always forget we can do operation with cents and it makes sense to store the value as integer and doing visual transformations for display. Now I just have to know how can I work with currencies that does not have cents at all, like PYG (Paraguay Guaranies). But thanks for the info.
I have a amount column in Voyager table and I want to display the values with decimal places and comma (like number_format($var, 2), e.g. 1,000.20). Is it possible?
Having the same issue, the number is getting rounded each time i try to save it in the database.
Version information
Description
If you create a field type decimal, you can't add precision, like 10,8
Steps To Reproduce
Create a field type decimal, if you try to add length to 10,8 it store as 10,0
Expected behavior
Should store decimal precision