PHP code example of jstewmc / evaluate-number
1. Go to this page and download the library: Download jstewmc/evaluate-number 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/ */
jstewmc / evaluate-number example snippets
namespace Jstewmc\EvaluateNumber;
// instantiate the service
$service = new EvaluateNumber();
// evaluate some stuff!
$service(true); // returns (int) 1
$service(1); // returns (int) 1
$service('1'); // returns (int) 1
$service(1.5); // returns (float) 1.5
$service('1.5'); // returns (float) 1.5
$service('1 1/2'); // returns (float) 1.5
$service('3/2'); // returns (float) 1.5
$service('3\2'); // returns (float) 1.5
$service('1000'); // returns (int) 1000
$service('1,000'); // returns (int) 1000
$service('1,000.5'); // returns (float) 1000.5
$service('1st'); // returns (int) 1
$service('second'); // returns (int) 2
$service('one hundred'); // returns (int) 100
$service('10%'); // returns (float) 0.1
$service('$1000') // returns (int) 1000
$service('1,0,0'); // returns 0
$service('abc'); // returns 0
$service(array()); // returns 0
$service(array('foo')); // returns 1
$service(new stdClass()); // returns 1
namespace Jstewmc\EvaluateNumber;
$service = new EvaluateNumber();
$service(-1); // returns (int) -1
$service(0); // returns (int) 0
$service(1); // returns (int) 1
namespace Jstewmc\EvaluateNumber;
$service = new EvaluateNumber();
$service(-1.0); // returns (float) -1.0
$service(0.0); // returns (float) 0.0
$service(1.0); // returns (float) 1.0
namespace Jstewmc\EvaluateNumber;
$service = new EvaluateNumber();
$service(true); // returns (int) 1
$service(false); // returns (int) 0
namespace Jstewmc\EvaluateNumber;
$service = new EvaluateNumber();
$service('1'); // returns (int) 1
$service('1,000'); // returns (int) 1000
$service('1/2'); // returns (float) 0.5
$service('1 1/2'); // returns (float) 1.5
$service('one hundred'); // returns (int) 100
$service('first'); // returns (int) 1
$service('1st'); // returns (int) 1
$service('1%'); // returns (float) 0.01
$service('$1,000'); // returns (int) 1000
$service('foo'); // returns (int) 0
namespace Jstewmc\EvaluateNumber;
$service = new EvaluateNumber();
$service([]); // returns 0
$service(['foo']); // returns 1
$service(['foo', 'bar']); // returns 1
namespace Jstewmc\EvaluateNumber;
$service = new EvaluateNumber();
$service(new SplObject()); // returns 1