mostafatalebi Posted March 12, 2013 Share Posted March 12, 2013 Hello everybody I have a super simple question I do a math operation (division) which result (naturally) in a long decimal trail. I need only one decimal. Example: 1.5 or 2.6 and not 3.08 or 5.457874. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/275542-precision-of-floating-point-numbers/ Share on other sites More sharing options...
AyKay47 Posted March 12, 2013 Share Posted March 12, 2013 Implement round with the second precision parameter set to 1 Link to comment https://forums.phpfreaks.com/topic/275542-precision-of-floating-point-numbers/#findComment-1418148 Share on other sites More sharing options...
Barand Posted March 12, 2013 Share Posted March 12, 2013 Also, there's a couple of alternatives when outputting the number $num = 3.456; // either echo number_format($num, 1); //--> 3.5 // or printf('%0.1f', $num); //--> 3.5 Link to comment https://forums.phpfreaks.com/topic/275542-precision-of-floating-point-numbers/#findComment-1418171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.