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
this worked for me.. round the field to 2 decimal places and then trim any trailing zeros
So that 2.10 is 2.1
If you are using PHP as the scripting language you may use the following:
Or use the PHP
floatval
function:Please use below function , it will take care of number having zero without decimal places i.e 150 etc....
Addendum:
Typically to call this would involve: SELECT FN_STRIP_TRAILING_ZER0(1.5);
Try this simply updated Query to remove decimal zeros
I had a similar problem in a situation where I could not modify the code nor the SQL query, but I was allowed to modify the database structure. So I changed the column format from DECIMAL to FLOAT and it solved my problem.
Taking fragments of the others answers in this page I came to this conclusion:
Cheers