Jump to content

PHP Number Problems


Cascadia11

Recommended Posts

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.

 

 

 

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.