Questions tagged [bcmath]

BC Math is a binary calculator for PHP which supports numbers of any size and precision, represented as strings.

BC Math is a binary calculator for PHP which supports numbers of any size and precision, represented as strings.

BC Math Functions

  • bcadd() ~ Add two arbitrary precision numbers
  • bccomp() ~ Compare two arbitrary precision numbers
  • bcdiv() ~ Divide two arbitrary precision numbers
  • bcmod() ~ Get modulus of an arbitrary precision number
  • bcmul() ~ Multiply two arbitrary precision number
  • bcpow() ~ Raise an arbitrary precision number to another
  • bcpowmod() ~ Raise an arbitrary precision number to another, reduced by a specified modulus
  • bcscale() ~ Set default scale parameter for all bc math functions
  • bcsqrt() ~ Get the square root of an arbitrary precision number
  • bcsub() ~ Subtract one arbitrary precision number from another
100 questions
2
votes
1 answer

Error using BCMath - Call to undefined method PEAR_Error::int2bin()

I am having this error while using BCMath - Fatal error: Call to undefined method PEAR_Error::int2bin() in login.php on line 23 I am trying to use Crypt_RSA and BCMath together. Here is my code -…
liamzebedee
  • 14,010
  • 21
  • 72
  • 118
2
votes
1 answer

Why subtraction doesn't work properly using bcmath?

Let's say I have $foo = bcsub(bcdiv(1, 3, 20), 0.00001, 20); it returns me 0.33333333333333333333 If I have $foo = bcsub(bcdiv(1, 3, 20), 0.0001, 20); it returns me 0.33323333333333333332 If I have $foo = bcsub(0.333333333333333333, 0.00001,…
Templar
  • 1,843
  • 7
  • 29
  • 42
2
votes
1 answer

BCMath code for converting Hex to Dec - Issues - A bug in code?

I have some issue with a code trying to convert Hex values into decimal one. No matter if it is small or large integer, sometimes, the function returns me the Hex converted to Dec with 8 ceros as trailing. For example: It should return 72500 and…
2
votes
0 answers

Enable bcmath module PHP 7.2 server CLI

I have installed the php bcmath module for 7.2 via the command: yum install php-bcmath I can see that it's there, but it's not in the php ini file when I check with command php -i How can I enable this module? Server is CentOS 7 running Plesk…
YorkieMagento
  • 336
  • 2
  • 9
  • 25
2
votes
1 answer

How to install bcmath on a debian:jessie php5.6?

I am running a linux instance on a docker container. It is a debian:jessie with a php 5.6. I want to install bcmath module, but I have no success. Does someone know how o do that? root@1419c032c35f:/etc/php5/fpm# apt install php5.6-bcmath Reading…
IgorAlves
  • 5,086
  • 10
  • 52
  • 83
2
votes
1 answer

BCmath php 64bit

i'm using BCmath to do math with 64 bit unsigned integers, i want to make a bcmath-object to a normal int (high, low part) how can i achieve that ? Thank you for your help
noway
  • 23
  • 2
2
votes
1 answer

Getting the modulo of two real numbers with BCMath

I would like to find out whether one real number is a multitude of the other one. I'm using BC-Math because the code is part of a larger system doing price calculations and using floats results in wrong results on multiple calculations due to the…
Sander Toonen
  • 3,463
  • 35
  • 54
2
votes
3 answers

Drupal 8 - Commerce Module - BC math PHP extension not found

I'm trying to install the commerce module in Drupal 8 however I get the error 'BC math PHP extension not found'. I've searched for this problem and tried different things such as editing the PHP.ini by adding 'bcmath.scale=2' however I still get the…
jake66
  • 35
  • 1
  • 5
2
votes
2 answers

Why negative zero does not compare equal to positive zero using bccomp in PHP?

I try comparing "+0.00000000000" with "+0.00000000000" using bccomp. I expect the result to be 0, but actually get a 1. $ cat bcmath.php $ php bcmath.php int(1) $
rox
  • 525
  • 7
  • 16
2
votes
1 answer

php - bcadd has different point precision

On my windows box when I run $SR = "0"; $SPR = "149"; $SR = bcadd($SR, $SPR); echo "$SR"; It outputs 149.0000000000 But when I upload the same code to my Linux host, the output is 149. Why?
Positivity
  • 5,406
  • 6
  • 41
  • 61
2
votes
2 answers

bash bcmath functions

I have two functions for GNU bc in a Bash script. BC_CEIL="define ceil(x) { if (x>0) { if (x%1>0) return x+(1-(x%1)) else return x } else return -1*floor(-1*x) }\n" BC_FLOOR="define floor(x) { if (x>0) return x-(x%1) else return -1*ceil(-1*x)…
Gordon
  • 1,844
  • 4
  • 17
  • 32
2
votes
2 answers

Why is bcmath in php 4.3 so much faster than php 5+?

Decided to run a quick test to see how bcmath operates on various versions of PHP, and noticed that the latest and greatest is lacking significantly in speed when compared to 4.3, I am wondering if anyone knows what the reason behind this is, and/or…
Kraang Prime
  • 9,981
  • 10
  • 58
  • 124
2
votes
1 answer

php calculate discount or tax

I'm trying to calculate a tax or discount value using BCMATH in PHP. I need 2 DECIMAL PLACES. Here's how i'm doing it: bcscale(2); $price = '60.67'; $discount = bcmul(bcdiv($price, 100), '3.8'); // calculate 3.8 percent from 60.67 // result is:…
Marius
  • 3,976
  • 5
  • 37
  • 52
2
votes
1 answer

javascript equivalent of bcpowmod

I'm coding a javascript version that can decode a RSA encryption I made in PHP. everything works fine except I don't have a javascript equivalent of bcpowmod. I used the PHP JS library for the other functions but it doesn't have bcpowmod. If I use…
Barry127
  • 1,212
  • 1
  • 12
  • 23
1
vote
0 answers

Can't install php7.4-bcmath on Ubuntu 18

There is a server on Ubuntu 18. Worth nginx and php 7.4 I need to install php7.4-bcmath Command: "sudo apt-get install php7.4-bcmath" keeps giving error: Reading package lists... Done Building dependency tree Reading state information... Done E:…