PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
mysql_query("SELECT avg( vote ) as average, sum( vote ) as total, count( vote ) as total_v FROM story_vote where sid = $poetryid") or die(mysql_error());
in result it shows me 3.00000 and i want it to show 3.0
ROUND(x) and ROUND(x,y)
Returns the value of x rounded to the nearest integer. ROUND can also accept an additional argument y that will round x to y decimal places.
select ROUND(14.492);
+---------------+
| ROUND(14.492) |
+---------------+
| 14 |
+---------------+
1 row in set (0.00 sec)
select ROUND(4.5002);
+---------------+
| ROUND(4.5002) |
+---------------+
| 5 |
+---------------+
1 row in set (0.00 sec)
select ROUND(-12.773);
+----------------+
| ROUND(-12.773) |
+----------------+
| -13 |
+----------------+
1 row in set (0.00 sec)
select ROUND(7.235651, 3);
+--------------------+
| ROUND(7.235651, 3) |
+--------------------+
| 7.236 |
+--------------------+
1 row in set (0.00 sec)
Actually you want to use ROUND() .. but make sure you use 2 arguments .. eg ROUND(columnname, 1). If your number is 1.678, and you use TRUNCATE(1.678,1) you'll get 1.6 .. if you use ROUND(1.678,1) you'll get 1.7. TRUNCATE() just chops off the rest of the number, it's very unlikely that's what you actually want.
If you're outputting the number to the screen rather than using it mathematically, consider using FORMAT() instead.