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
0
votes
2 answers

Bcmath adding decimal places randomly

I have a PHP function I got from the web that uses bcmath functions: function SteamID64to32($steamId64) { $iServer = "1"; if(bcmod($steamId64, "2") == "0") { $iServer = "0"; } $steamId64 = bcsub($steamId64,$iServer); …
bockzior
  • 199
  • 1
  • 6
  • 20
0
votes
2 answers

Why is bcdiv always returning 0?

I have a small issue with BIG numbers where BC Maths function bcdiv is always returning zero on non-zero results. For example : echo bcdiv(40075036, 86164.098903691, 40); Versus the traditional method : echo (40075036/86164.098903691); I am not…
Kraang Prime
  • 9,981
  • 10
  • 58
  • 124
0
votes
1 answer

bcdiv minimum left/right operand

echo bcdiv(0.0001, 86400, 30); This code echos: 0.000000001157407407407407407407 echo bcdiv(0.00001, 86400, 30); And this code echos: 0.000000000000000000000000000000 Why is that? Is there a minimum value for both operands? I need to divide…
user2536244
0
votes
1 answer

PHP money calculation precision

I have a project that stores money as bigint column in a database (storing in cents). I'm planning to rewrite this thing to use BCMATH instead. I don't mind integers, but they give me some terrible rounding errors event stored in cents and I suspect…
Marius
  • 3,976
  • 5
  • 37
  • 52
0
votes
0 answers

How to use infinities with BC Math in php?

I cannot find how to use infinities with BC Math. Let's take something like: $result = echo bcdiv("1", $divider); It goes all well until $divider is 0. So you make an exception: if (!bccomp($divider, "0")) { $result = echo bcdiv("1",…
-1
votes
2 answers

PHP BC Math library ignore rounding rules

I'm using bcdiv function from PHP to calculate some things, but result is different than it should be. Here is sample code: $val1 = 599.60; $val2 = 60; var_dump(bcdiv($val1, $val2, 0)); // result string(1) "9" // should be…
ptyskju
  • 175
  • 1
  • 3
  • 18
-1
votes
1 answer

Why is Bcmath returning innacurate results

Im having trouble getting bcmath to work with bitcoin based fractions on my server php 7.1 , ubuntu 18. Look at the following Code bcscale(8); $x1 = bcsub(0.04217 ,0.00007, 8); $x2 = 0.04217 - 0.00007 ; dd($x1 , $x2); Result "0.04217000" 0.0421 As…
ofumbi
  • 334
  • 1
  • 4
  • 11
-1
votes
1 answer

why is php bccomp equal?

php version 5.4.33 php.ini: bcmath.scale = 0 (also tried bcmath.scale = PHP_INI_ALL) problem: php5433 -r "echo bccomp(0.00000001, 0, 9);" print 0 php5433 -r "echo bccomp(1.00000001, 1, 9);" print 1 why? Anyone can help?
Young
  • 1
-2
votes
2 answers

Converting float to string without exponential notation

I'm looking for a way to convert a float value to string in PHP without exponential (scientific) notation. I need it in order to use bcmath, which doesn't support exponential notation.
Mikhail Prosalov
  • 4,155
  • 4
  • 29
  • 41
-2
votes
1 answer

Why does my bc-math doesn't work?

In my function I want to use php bc-math to improve the precision. I've tried to replace all operations to no avail. Is this is a float-to-string conversion problem? function complex_iterate($re,$im) { $re=strval($re); …
Micromega
  • 12,486
  • 7
  • 35
  • 72
1 2 3 4 5 6
7