Cascadia11 Posted November 20, 2013 Share Posted November 20, 2013 Hi, I have a string, say for instance 0.001 I need to split this amount into two different amounts - one with 1.5% and the other with 98.5%. What I need is the returning amounts in the same format, so like this... 1.5% = 0.000015 98.5% = 0.000985 But when I do the calculation in PHP using this code. $total_amount = 0.001; $percentage = 1.5; $new_amount = ($percentage / 100) * $total_amount; I end up getting 5.0E-6 What am I doing wrong? I am honestly very bad when it comes to basic mathematics. This has been driving me insane all day. I've tried converting that produced power number into the correct format but to no success. Thank you so much for any help. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 20, 2013 Share Posted November 20, 2013 $ php -a Interactive shell php > $total_amount = 0.001; php > $percentage = 1.5; php > $new_amount = ($percentage / 100) * $total_amount; php > echo $new_amount; 1.5E-5 php > Quote Link to comment Share on other sites More sharing options...
Cascadia11 Posted November 20, 2013 Author Share Posted November 20, 2013 Sorry, I have no idea what Interactive Shell is or how to use it. Is there anything I can do to figure this out? Quote Link to comment Share on other sites More sharing options...
requinix Posted November 20, 2013 Share Posted November 20, 2013 I was just demonstrating how the code you posted works correctly for me: $new_amount = 0.000015. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 20, 2013 Share Posted November 20, 2013 @Requinix, I think his problem is he doesn't know how to deal with the exponential returned value @Cascadia11, the value you state is being returned is the wrong value. You're getting back .000005 - which makes no sense. Once you are getting the right value, try using this to format it: http://php.net/manual/en/function.number-format.php 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.