mehmetriza / numbery
PHP字符串转数字和验证转换函数
1.0.0
2023-06-19 07:49 UTC
Requires
- php: >=7.3
Requires (Dev)
- phpunit/phpunit: 10
README
PHP字符串转数字和验证转换函数
安装
composer require mehmetriza/numbery
用法
require "vendor/autoload.php"; Numbery::parse("$1.000,00 adam") // string number ->decimal(2,true) // decimal count, optional (true|false) ->decimalSeparator(',') // using decimal operator ->thousandsSeparator('.') // thousand seperator chracter ->prefix('$',true) // prefix chracter, is optional (true|false) ->suffix(' adam',false) // suffix chracter, is optional (true|false) ->convert(); //return double
示例 1
$a = '$123,45 adam'; Numbery::parse($a) ->decimal(2,true) ->decimalSeparator(',') ->thousandsSeparator('.') ->prefix('$',true) ->suffix(' adam',false) ->convert(); // return 123.45 -> double
示例 2
$a = "100.855.555"; Numbery::parse($a) ->decimal(5,true) ->thousandsSeparator('.') ->convert(); // return 100855555 -> double
如果你想要返回的数据类型为整数
$value = int Numbery::parse($a) ->decimal(5,true) ->thousandsSeparator('.') ->convert();
异常
throws an error if it doesn't conform to conditions
new NumericException; new DecimalException; new PrefixException; new SuffixException; new ThousandException;