Tools, FAQ, Tutorials:
Converting Strings to Numbers in PHP
How To Convert Strings to Numbers?
✍: 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
⇒ PHP Built-in Functions for Strings
⇐ Converting Numbers to Strings in PHP
2016-10-13, 1563🔥, 0💬
Popular Posts:
Where to see resource detailed information of my API Management Service on Azure Portal? Once you ha...
How to include additional claims in Azure AD v2.0 id_tokens? If you want to include additional claim...
How to login to Azure API Management Publisher Dashboard? If you have given access permission to an ...
How To Break a File Path Name into Parts in PHP? If you have a file name, and want to get different ...
How to use the "@(...)" expression in Azure API Policy? The "@(...)" expression in Azure API Policy ...