I have a procedure I am doing that displays odds but the client wants only significant digits to be shown. So, 1.50 would show as '1.5' and 1.00 would show as '1'.
How can I get MySQL to not display trailing zeros;
i.e. in the database:
Odds
1.500
23.030
2.000
4.450
would display as
1.5
23.03
2
4.45
Thanks for any help
The best solution I found is to cast your round value to FLOAT:
Taking forward the answer provided by @fooquency, if the column is already declared as a DECIMAL with a non-zero value for D in DECIMAL(M, D), we do not need to perform the WHERE condition
as the values in the column will always contain D digits after the decimal dot (.)
Using ROUND or CEILING, in the query you just have to type:
or
or
work ok but require a "where" clause.
I think the best solution is probably:
as it doesn't require a "where" clause, doesn't require any special code, and also lets you set the maximum precision of the number upfront.
Easiest way by far, just add zero!
Examples:
If the column your value comes from is DECIMAL or NUMERIC type, then cast it to string first to make sure the conversion takes place...ex:
For a shorter way, just use any built-in string function to do the cast:
Here's what worked for me:
SINGLE COLUMN:
MULTIPLE COLUMNS: