-
-
Notifications
You must be signed in to change notification settings - Fork 108
Numeric/Decimal type return as float #257
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
Comments
Why should it return decimal as a string? |
Because these types are generally used for storing money, and we never use floats for money. Php does not have a built-in money format, so the only way out is a string. At first example with PDO you can see the right way. |
To be more precise: Because PHP doesn't support the decimal type that follows fixed-point arithmetic (instead of floating-point arithmetic). Currently in PHP for serious financial stuff (such as accounting software) the only reliable way is string + BCMath (indeed bc* functions work on strings).
Furthermore, usually decimal/numeric types can reach very large numbers (PostgreSQL numeric type range is described as "up to 131072 digits before the decimal point; up to 16383 digits after the decimal point"). String + BCMath is the only way to deal with decimals. |
I understand, but it is huge BC break… |
May be it be possible to add a mode selection as an option? Something like $db = new Nette\Database\Connection(...);
$db->setDecimalMode(Mode::AS_STRING); The string will only be returned if set explicitly, and this will save BC |
A more general way is being able to change the row normalization with a custom implementation. There is already a PR here #138. |
When working with money, I'm using explicit type casting to string |
I added the option to configure row normalizer to disable conversion of numeric types to floats. $db = new Nette\Database\Connection(...);
$db->setRowNormalizer((new Nette\Database\RowNormalizer)->skipNumeric()); |
Version: v3.0.5
Bug Description
Numeric/Decimal type return as
float
insteadstring
Steps To Reproduce
after run php code we got
Expected Behavior
Possible Solution
I think
float
must return only if db field type isfloat
ordouble
The text was updated successfully, but these errors were encountered: