PHP code example of mvccore / ext-tool-locale-floatparser
1. Go to this page and download the library: Download mvccore/ext-tool-locale-floatparser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mvccore / ext-tool-locale-floatparser example snippets
$autoParser = \MvcCore\Ext\Tools\Locales\FloatParser::CreateInstance(
'en', // international language code, lowercase
'US', // international country code, uppercase
FALSE // FALSE (by default) to prefer automatic floating point detection
);
var_dump($autoParser->Parse('-1,234,567.89')); // -1234567.89 (float)
var_dump($autoParser->Parse('-1.234.567,89')); // -1234567.89 (float)
var_dump($autoParser->Parse('-1 234 567.89')); // -1234567.89 (float)
var_dump($autoParser->Parse('-1 234 567,89')); // -1234567.89 (float)
var_dump($autoParser->Parse('1.2 3 and 4')); // 1.234 (float)
var_dump($autoParser->Parse('1.2 3')); // 1.23 (float)
// rest is the same as `Intl` floating point parser bellow:
var_dump($autoParser->Parse('1.8e308')); // INF (float)
var_dump($autoParser->Parse('1.79e308')); // 1.79E+308 (float)
var_dump($autoParser->Parse('21474836470')); // 21474836470 (float)
var_dump($autoParser->Parse('123')); // 123.0 (float)
var_dump($autoParser->Parse('-3.14')); // -3.14 (float)
var_dump($autoParser->Parse('1.2e3')); // 1200 (float)
var_dump($autoParser->Parse('7E-10')); // 7.0E-10 (float)
var_dump($autoParser->Parse('bob-1.3e3')); // -1300 (float)
var_dump($autoParser->Parse('nothing')); // NULL
var_dump($autoParser->Parse(TRUE)); // NULL
var_dump($autoParser->Parse([])); // NULL
var_dump($autoParser->Parse(new \stdClass)); // NULL
$intlParser = \MvcCore\Ext\Tools\Locales\FloatParser::CreateInstance(
'en', // international language code, lowercase
'US', // international country code, uppercase
TRUE // TRUE to prefer `Intl` extension parsing
);
var_dump($intlParser->Parse('-1,234,567.89')); // -1234567.89 (float)
var_dump($intlParser->Parse('-1 234 567,89')); // -1234567 (float)
var_dump($intlParser->Parse('-1 234 567.89')); // -1234567.89 (float)
var_dump($intlParser->Parse('-1 234 567,89')); // -1234567 (float)
var_dump($intlParser->Parse('1.2 3 and 4')); // 1.2 (float)
var_dump($intlParser->Parse('1.2 3')); // 1.2 (float)
// rest is the same as non `Intl` floating point parser above:
var_dump($autoParser->Parse('1.8e308')); // INF (float)
var_dump($autoParser->Parse('1.79e308')); // 1.79E+308 (float)
var_dump($autoParser->Parse('21474836470')); // 21474836470 (float)
var_dump($intlParser->Parse('123')); // 123.0 (float)
var_dump($intlParser->Parse('-3.14')); // -3.14 (float)
var_dump($intlParser->Parse('1.2e3')); // 1200 (float)
var_dump($intlParser->Parse('7E-10')); // 7.0E-10 (float)
var_dump($intlParser->Parse('bob-1.3e3')); // -1300 (float)
var_dump($intlParser->Parse('nothing')); // NULL
var_dump($intlParser->Parse(TRUE)); // NULL
var_dump($intlParser->Parse([])); // NULL
var_dump($intlParser->Parse(new \stdClass)); // NULL
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.