PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
andrew99
Forum Newbie
Posts: 7 Joined: Mon Dec 08, 2003 9:01 am
Post
by andrew99 » Tue Jan 13, 2004 3:52 am
I have a var with a value of 35.00.
I want it to increase by 15% so i wrote
Code: Select all
<?php
$new_var = $old_var*1,15; //error
// or
$new_var = $old_var*1.15; // error
//or
$new_var = $old_var+($old_var*15/100); // new value is irrelevant 34.5
?>
where i am wrong? the original value is from a mysql db stored as (decimal 8,2).
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Tue Jan 13, 2004 4:08 am
what error are you getting because
works for me
Mark
andrew99
Forum Newbie
Posts: 7 Joined: Mon Dec 08, 2003 9:01 am
Post
by andrew99 » Tue Jan 13, 2004 4:15 am
with
$new_var = $old_var*1.15;
and $old_var=35.00
i get a result of 34.5 instead of 40.25
ERROR!!
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Tue Jan 13, 2004 4:49 am
the result i get is 40.25
Weird!
Mark
krash_control
Forum Newbie
Posts: 14 Joined: Mon Jan 12, 2004 10:02 am
Location: United Kingdom
Contact:
Post
by krash_control » Tue Jan 13, 2004 4:55 am
I get the same as Bech100
Just wondering if this could have anything to do with the type of old_var? I am still a bit new to PHP but is there such a thing as type casting in PHP. That is, converting $old_var to integer or double to make sure it calculates correctly
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Tue Jan 13, 2004 5:11 am
you can type cast, but usually it isn't neccessary
check out [php_man]settype()[/php_man]
Mark
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Tue Jan 13, 2004 10:05 am
Sounds like time to check if $old_var really does have the value you expect:
Code: Select all
<?php
echo $old_var . '<br />';
$new_var = $old_var*1.15;
?>