Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Convert Strings to Numbers
How To Convert Strings to Numbers? - PHP Script Tips - Understanding String Literals and Operations
✍: FYIcenter.com
In 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:
Here is a PHP script example of converting some examples:
<?php $foo = 1 + "10.5"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 1 + "-1.3e3"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 1 + "bob-1.3e3"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 1 + "bob3"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 1 + "10 Small Pigs"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = 4 + "10.2 Little Piggies"; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = "10.0 pigs " + 1; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; $foo = "10.0 pigs " + 1.0; echo "\$foo=$foo; type is " . gettype ($foo) . "\n"; ?>
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
2007-04-20, 4952👍, 0💬
Popular Posts:
What is the FP per day in your current company?
Can Multiple Cursors Being Opened at the Same Time? - Oracle DBA FAQ - Working with Cursors in PL/SQ...
What is synchronization and why is it important? With respect to multithreading, synchronization is ...
What Is a LABEL Tag/Element? - XHTML 1.0 Tutorials - Understanding Forms and Input Fields A "label" ...
How To Delete a User Account? - Oracle DBA FAQ - Managing Oracle User Accounts, Schema and Privilege...