HTTPS SSH

BN-PHP

About

  • Big Number data type for PHP.
  • Data type which can be used as replacement of inaccurate float
  • Use BC Math.
  • Included Math expressions parser for infix notation.
  • Requirements: PHP >= 5.3.
  • Class API

Example usage

In PHP or any other programming language floating point precision is a problem. For example result of operator floor((0.1+0.7)*10) is 7 instead of the expected 8. BN-PHP always returns 8.

BN-PHP vs eval

Basic usage of BN\Number data type

$a = new BN\Number('0.1');
$b = new BN\Number('0.7');
$ten = new BN\Number('10');
echo $a->add($b)->multiply($ten)->roundDown();

Expression evaluator in action

$evaluator('floor((0.1+0.7)*10)', $variables, $responder);

For more examples and documentation check wiki.

Facts

License: New BSD License.

Author: Zdenek Drahos.