Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Coding/Programming Interviews:Active Template Library (ATL)ActiveXApplication DeveloperArtificial intelligenceAssemblyAssociate Software EngineerAWKAWTC ProgrammingC++ ProgrammingCGI PerlCGI ProgrammingCMMICobolCritical ReasoningData Structures TreesDCOM COMDelphiDTDE4XExtensible Stylesheet Language (XSL)FortranFull-Stack DeveloperHaskellHTML DOMILUIPhone DeveloperJasper Reports DeveloperJava DeveloperLisp ProgrammingLotus NotesMicrosoft Foundation Class (MFC)Mobile DeveloperMVC DeveloperNode.jsOOPPascalPerl ProgrammingPHPPHP DeveloperProgrammingProgramming AlgorithmsProgramming ConceptsPythonRubyRuby on RailsRuby on Rails DeveloperSenior Front End DeveloperSenior Software DeveloperSignature ProgramSOASocket ProgrammingSoftware Development EngineerSoftware engineeringSr. PHP ProgrammerStack And QueueSTLSwift DeveloperTCL (Tool Command Language)Team Leader Android DeveloperUMLUnity 2D Games DeveloperUnity 3D DeveloperUnity DeveloperVBA (Visual Basic for Applications)Visual Basic (VB)Visual C++Web DevelopmentWin32APIWindows ProgramingWordPress DevelopmentWSDLXFormsXHTMLXLinkXMLXPathXQueryXSL-FOXSLT
Copyright © 2018. All Rights Reserved
PHP Interview Question:
How To Convert Strings to Numbers in PHP?
Submitted by: AdministratorIn a numeric context, PHP will automatically convert any string to a numeric value. Strings will be converted into two types of numeric values, double floating number and integer, based on the following rules:
► The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero).
► If the valid numeric data contains '.', 'e', or 'E', it will be converted to a double floating number. Otherwise, it will be converted to an integer.
Submitted by: Administrator
► The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero).
► If the valid numeric data contains '.', 'e', or 'E', it will be converted to a double floating number. Otherwise, it will be converted to an integer.
Submitted by: Administrator
Here is a PHP script example of converting some examples:
<?php
$foo = 1 + "10.5";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 1 + "-1.3e3";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 1 + "bob-1.3e3";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 1 + "bob3";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 1 + "10 Small Pigs";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 4 + "10.2 Little Piggies";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = "10.0 pigs " + 1;
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = "10.0 pigs " + 1.0;
echo "$foo=$foo; type is " . gettype ($foo) . " ";
?>
This script will print:
$foo=11.5; type is double
$foo=-1299; type is double
$foo=1; type is integer
$foo=1; type is integer
$foo=11; type is integer
$foo=14.2; type is double
$foo=11; type is double
$foo=11; type is double
Submitted by: Administrator
<?php
$foo = 1 + "10.5";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 1 + "-1.3e3";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 1 + "bob-1.3e3";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 1 + "bob3";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 1 + "10 Small Pigs";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = 4 + "10.2 Little Piggies";
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = "10.0 pigs " + 1;
echo "$foo=$foo; type is " . gettype ($foo) . " ";
$foo = "10.0 pigs " + 1.0;
echo "$foo=$foo; type is " . gettype ($foo) . " ";
?>
This script will print:
$foo=11.5; type is double
$foo=-1299; type is double
$foo=1; type is integer
$foo=1; type is integer
$foo=11; type is integer
$foo=14.2; type is double
$foo=11; type is double
$foo=11; type is double
Submitted by: Administrator
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.