division in php
$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 ?
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;
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.
Err... I'm sure it's typo, but I think you meant
$newValue = $newValue / 0.0125
$newValue = $newValue/0.0125;
精彩评论