Skip to content
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

sum() sometimes returns string instead of number #1083

Closed
m-nienberg opened this issue Apr 28, 2023 · 1 comment
Closed

sum() sometimes returns string instead of number #1083

m-nienberg opened this issue Apr 28, 2023 · 1 comment

Comments

@m-nienberg
Copy link

If the sum() functions doesn't find any matches it returns an empty string. I suggest it would be better to return zero. Otherwise you can get a fatal error if you try to use the result in a function that will not accept a string.

$total = $database->sum("account", "money", ["currency" => "dollars"]); 
echo "We have $" . number_format($total, 0);   <--- fatal error

The documentation at https://medoo.in/api/sum says that the return will be a number.
I haven't tested, but the same may be true for the other Aggregation functions.

@catfan
Copy link
Owner

catfan commented Apr 28, 2023

That's the document problem. I have fixed it. 4cb6410

Those aggregate methods will return a string. You have to cast it to float or integer. Zero will not be correct in some cases.

@catfan catfan closed this as completed Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants