Skip to content

This is a polyfill to allow the BcMath\Number class, introduced in PHP 8.4, to be used in PHP 8.3 and 8.2.

License

Notifications You must be signed in to change notification settings

SakiTakamachi/BcMath-Number-Polyfill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BcMath\Number Polyfill

Latest Stable Version Push codecov License PHP Version Require

Install

composer require saki/bcmath-number-polyfill

This library requires the BCMath extension. Also, since this is a polyfill, it does not support PHP 8.4 or higher. For PHP 8.2 and 8.3 only.

Description

This is a polyfill for BcMath\Number class added in PHP 8.4. It achieves the same behavior as much as possible, but does not support operator overloading.

RoundingMode Enum is also included. However, if it has already been defined, it will not be defined twice.

New functions such as bcround() are not included in this library.

How to use

You can treat it like anything added in PHP 8.4.

use BcMath\Number;

$number = new Number('1.23');
$rounded = $number->round(1, RoundingMode::AwayFromZero);

var_dump($rounded);

result:

object(BcMath\Number)#3 (2) {
  ["value"]=>
  string(3) "1.3"
  ["scale"]=>
  int(1)
}

About

This is a polyfill to allow the BcMath\Number class, introduced in PHP 8.4, to be used in PHP 8.3 and 8.2.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages