开发者

division in php

开发者 https://www.devze.com 2023-01-27 10:37 出处:网络
$voltage = \'0.4000\'; $newValue = str_replace(\'0.\',\'\',$voltage); echo \'newvalue\'.$newValue; $newValue = $voltage/0.0125;
 $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;
0

精彩评论

暂无评论...
验证码 换一张
取 消