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 ?

Answers


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.


Need Your Help

Do the Google App Engine OAuth endpoints support OAuth 2.0?

google-app-engine authentication oauth oauth-2.0

Do the OAuth endpoints provided by Google App Engine (eg https://app-id.appspot.com/_ah/OAuthGetRequestToken) support OAuth 2?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.