PHP Classes


Recommend this page to a friend!
  Classes of Kacper Rowinski  >  PHP BCMath Extension  >  >  Download  
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PHP BCMath Extension
Add missing functions missing in BCMath
Author: By
Last change: - cleanup some old php 5.6 fixes
- added move validation for powMod
- changed naming and params to be more in self explaining (breaking changes!)
- code optimisation
- changed self to static (#36)
- added ability to trim trailing zeros (#36)
- little code cleanup
Date: 1 year ago
Size: 2,711 bytes


Class file image Download


Build Status Code Coverage Latest Stable Version Total Downloads Latest Unstable Version License

Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions. (more


composer require krowinski/bcmath-extended


  • config - setTrimTrailingZeroes - disable|enable trailing zeros (default trimming is enabled)
  • new tool methods - convertScientificNotationToString - converts scientific notation to string - getScale - gets current global scale - getDecimalsLengthFromNumber - gets amount of decimals - hexdec - converting from hexadecimal to decimal - dechex - converting from decimal to hexadecimal - bin2dec - converting from binary to decimal - dec2bin - converting from decimal to binary
  • new math functions - round - abs - rand - max - min - roundDown - roundUp - roundHalfEven - ceil - exp - log - fact - pow (supports fractional) - mod (supports fractional + scale in php 5.6 <) - bitwise operators - bitXor - bitOr - bitAnd
  • proxy for original functions (
  • all functions supports scientific notation
  • all functions are static, so it can be easy replaced by this lib


As of 7.2 float can be passed to bcmod but they don't return correct values (IMO)

I created bug for this in but it was commented as documentation issue not a bug.

bcmod() doesn't use floor() but rather truncates towards zero,
which is also defined this way for POSIX fmod(), so that the
result always has the same sign as the dividend.  Therefore, this
is not a bug, but rather a documentation issue.

But I still will use floor not truncated for mod in this lib.

For more information send a message to info at phpclasses dot org.