Jarod Posted January 24, 2010 Share Posted January 24, 2010 Okay I've done the math, but I want to turn it around to a smaller number, this is how my math goes though: Basically I have the number 0.778%, I want to turn that around to 7.78% though, is this possible? To get 0.778 I want did 309 divided by 397. Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2010 Share Posted January 24, 2010 I'm not great at maths but does this achieve what you want? $val = 309 / 397; echo number_format($val * 10, 2); Seems awfully simple so I'm not confident in my answer! Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 24, 2010 Share Posted January 24, 2010 To move the decimal place by one multiply by 10 echo (309 / 397) * 10; Okay I've done the math, but I want to turn it around to a smaller number, 7.78% is not smaller than 0.778% Quote Link to comment Share on other sites More sharing options...
Jarod Posted January 24, 2010 Author Share Posted January 24, 2010 To move the decimal place by one multiply by 10 echo (309 / 397) * 10; Okay I've done the math, but I want to turn it around to a smaller number, 7.78% is not smaller than 0.778% I know it's bigger, which is why i mention manipulation. I want to manipulate it as 7.78, basically make it into a collusion. EDIT: I think substr() might be of use, should be, ill try it. Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 I am an old C programmer so I prefer the C-like functions in php, and I would do this $ans = sprintf("%0.2f", 309 / 397); gives 0.78 Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 or if you want 10 times that, also formatted to 2 decimal places $ans = sprintf("%0.2f", 309 / 397 * 10); 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.