leachus2002 Posted December 13, 2010 Share Posted December 13, 2010 Hi All, I am trying to work out some simple maths between 2 numbers, that are returned in variables - say $v1 and $v2. $v2 = 126 and $v1 = 318 I can do the working out - $total = $v2 / $v1 * 100 However is there any way that I can set total to only display the first 2 numbers? Just that I am getting a long result cause of the decimal places. (39.62264150943396..........) Can it be done? Thanks Matt Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 13, 2010 Share Posted December 13, 2010 I believe the round function is what you are looking for! http://php.net/manual/en/function.round.php if you want to round up or down, ceil() is up and floor() is down. If you only want some decimals, this function would be worth looking into: http://php.net/manual/en/function.number-format.php else you can always round($number*10)/10; for example to get 1 decimal. Quote Link to comment 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.