Reputation: 7906
$voltage = '0.4000';
$newValue = str_replace('0.','',$voltage);
echo 'newvalue'.$newValue;
$newValue = $voltage/0.0125;
echo 'newvalue'.$newValue;
when i do like this i get 32 after division where as i should get 320000. any problem in wht i am doing ?
Upvotes: 0
Views: 152
Reputation: 60413
If youre doing number opertations then use numeric functions and varibles not strings...
$voltage = (float) '0.4000'; //cast as a float, assuming this comes from user input as string
$newValue = $volatge*1000;
echo 'newvalue'.$newValue;
$newValue = $newValue/0.0125;
echo 'newvalue'.$newValue;
Upvotes: 3
Reputation: 60506
Err... I'm sure it's typo, but I think you meant
$newValue = $newValue / 0.0125
Upvotes: 1
Reputation: 16771
You said $newValue = $voltage/0.0125
. You probably meant to say $newValue = $newValue/0.0125
You never changed $voltage
so it's still 0.4000, not 4000.
Upvotes: 3