mehmetriza/numbery

Php string to number and validation convert function

1.0.0 2023-06-19 07:49 UTC

This package is auto-updated.

Last update: 2025-06-29 02:17:17 UTC


README

Php string to number and validation convert function


install

composer require mehmetriza/numbery

Usage

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


Example 1


    $a = '$123,45 adam';

    Numbery::parse($a)
        ->decimal(2,true) 
        ->decimalSeparator(',') 
        ->thousandsSeparator('.') 
        ->prefix('$',true) 
        ->suffix(' adam',false)
        ->convert();

    // return 123.45 -> double

Example 2


$a = "100.855.555";

Numbery::parse($a)
    ->decimal(5,true)
    ->thousandsSeparator('.')
    ->convert();

// return 100855555 -> double

if you want the return data type integer

$value = int Numbery::parse($a)
    ->decimal(5,true)
    ->thousandsSeparator('.')
    ->convert();

Exceptions

throws an error if it doesn't conform to conditions
new NumericException;
new DecimalException;
new PrefixException;
new SuffixException;
new ThousandException;