common Posted February 17, 2009 Share Posted February 17, 2009 hi i'm busy with a php practical and need help with decimal numbers. The worked out a sum and its answer displays 18.5953893. I need it show only 2 numbers after the break, like 18.60 Can anyone help me plz?? Quote Link to comment https://forums.phpfreaks.com/topic/145624-decimal-numbers/ Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 Try this ;-) www.php.net/number-format Quote Link to comment https://forums.phpfreaks.com/topic/145624-decimal-numbers/#findComment-764506 Share on other sites More sharing options...
Brian W Posted February 17, 2009 Share Posted February 17, 2009 round($number, 2) will return the number rounded to two decimal points. floor() & ceil () I think do it too. Quote Link to comment https://forums.phpfreaks.com/topic/145624-decimal-numbers/#findComment-764507 Share on other sites More sharing options...
allworknoplay Posted February 17, 2009 Share Posted February 17, 2009 hi i'm busy with a php practical and need help with decimal numbers. The worked out a sum and its answer displays 18.5953893. I need it show only 2 numbers after the break, like 18.60 Can anyone help me please?? $number = 18.5953893; $new_number = number_format($number); Quote Link to comment https://forums.phpfreaks.com/topic/145624-decimal-numbers/#findComment-764509 Share on other sites More sharing options...
common Posted February 17, 2009 Author Share Posted February 17, 2009 thanks i used the round($number,2) and it works. thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/145624-decimal-numbers/#findComment-764517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.