Darla Posted February 18, 2007 Share Posted February 18, 2007 Hello I am wondering if there are any ways to remove extra decimals in php (or alternatively in sql)? I fetch aome average values from a table, and I wish to keep only one decimal or remove decimals entirely. Ex: 14.6154 should be 14.6 og just 14. Are there any "ready-to-use" functions for this in php/mysql? Darla Link to comment https://forums.phpfreaks.com/topic/39038-solved-how-to-remove-decimals-in-php-sql/ Share on other sites More sharing options...
printf Posted February 18, 2007 Share Posted February 18, 2007 // mysql 14.6154 would become 14.6 SELECT ROUND(decimal_column, 1) AS rounded_number FROM ...; // php $number = 14.6154; echo round ( $number, 1 ); // prints 14.6 dont include the second argument , 1 to return a rounded whole number (no decimal) printf Link to comment https://forums.phpfreaks.com/topic/39038-solved-how-to-remove-decimals-in-php-sql/#findComment-188025 Share on other sites More sharing options...
Darla Posted February 18, 2007 Author Share Posted February 18, 2007 Thanks! That worked perfectly Link to comment https://forums.phpfreaks.com/topic/39038-solved-how-to-remove-decimals-in-php-sql/#findComment-188029 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.