Page 1 of 1

multiply help

Posted: Tue Jan 13, 2004 3:52 am
by andrew99
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).

Posted: Tue Jan 13, 2004 4:08 am
by JayBird
what error are you getting because

Code: Select all

$new_var = $old_var*1.15;
works for me

Mark

Posted: Tue Jan 13, 2004 4:15 am
by andrew99
with

$new_var = $old_var*1.15;

and $old_var=35.00

i get a result of 34.5 instead of 40.25

ERROR!!

Posted: Tue Jan 13, 2004 4:49 am
by JayBird
the result i get is 40.25

Weird!

Mark

Posted: Tue Jan 13, 2004 4:55 am
by krash_control
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

Posted: Tue Jan 13, 2004 5:11 am
by JayBird
you can type cast, but usually it isn't neccessary

check out [php_man]settype()[/php_man]

Mark

Posted: Tue Jan 13, 2004 10:05 am
by McGruff
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; 
?>