Jump to content

Working with numbers and percents


DBookatay

Recommended Posts

Someone help, before I pull the rest of my hair out of my head...

I am attempting to create an accounting DB and need help with a line of code.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$balance = ($_POST['soldAmt']) + ($_POST['soldFees']) * ($_POST['rate']) - ($_POST['down']); [/quote]

Basically what Im trying to say is the "balance = soldAmt + soldFees x rate (which is %) - down. I'm having trouble turning ($_POST['rate']) into a percentage, and then x (multiply) it by ($_POST['soldAmt']) + ($_POST['soldFees']) - ($_POST['down'])

Any help?
Link to comment
Share on other sites

[!--quoteo(post=382091:date=Jun 9 2006, 07:05 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 9 2006, 07:05 PM) [snapback]382091[/snapback][/div][div class=\'quotemain\'][!--quotec--]
That's basic math... But do you want to

1. ADD the percentage: $value * (1 + $rate/100);
2. SUBTRACT the percentage: $value * (1 - $rate/100)
3. or simply GET the adjusted value: $value * $rate/100
[/quote]



"soldAmt" + "soldFees" + "rate" = _______ - "down"
Link to comment
Share on other sites

I still don't understand, but I'll assume:

[code]<?php

$balance = ($_POST['soldAmt'] + $_POST['soldFees']) * (1 + $_POST['rate']/100) - $_POST['down'];
echo 'Balance: ' . $balance;

?>

<form action="" method="post">
soldAmt: <input type="text" name="soldAmt" value="<?=$_POST['soldAmt']?>"><br />
soldFees: <input type="text" name="soldFees" value="<?=$_POST['soldFees']?>"><br />
rate: <input type="text" name="rate" value="<?=$_POST['rate']?>"><br />
down: <input type="text" name="down" value="<?=$_POST['down']?>"><br />
<input type="submit">
</form>[/code]

For soldAmt = 200, soldFees = 100, rate = 5, down = 40 it gives you balance = 275

[b]EDIT:[/b] 666th post...
Link to comment
Share on other sites

[!--quoteo(post=382103:date=Jun 9 2006, 07:36 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 9 2006, 07:36 PM) [snapback]382103[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[b]EDIT:[/b] 666th post...
[/quote]

Thanks for the help, Satan!


One more quick question, my "balance" row is "float" and if I insert $30.70 it inserts it into the db as 30.7.
How do I change this:
[code]$balance = '$ ' . $row['balance'];[/code] so that when it displays it will show again as $30.70.
Or if it's an even $30, how do I make it $30.00?
Link to comment
Share on other sites

[!--quoteo(post=382107:date=Jun 9 2006, 08:00 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 9 2006, 08:00 PM) [snapback]382107[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Use the [a href=\"http://www.php.net/number_format\" target=\"_blank\"]number_format()[/a] function when displaying your numbers.

Ken
[/quote]

I tried that:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$balance = '$ ' . number_format($row['balance']);[/quote]

but then it takes off the cents leaving me with only a whole dollar ammount...
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.