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

PHP: Install bcmath mdoule to specific version of php

I have 2 versions of php5.6 installed in my Ubuntu16.0.4. One is ZTS(Zend Thread Safety) enabled and another does not have zts. I want to install bcmath module to php-zts version. I used "apt install php5.6-bcmath" to install the module.…
vishwas tej
  • 139
  • 1
  • 13
0
votes
1 answer

PHP: Does BCMath accept integers?

Is it safe to use INT-type variables in BCMath functions in PHP ? Example: This seems to work but is it safe to do this ? Or is there for example a risk that PHP can interpret an INT as something else…
abc
  • 125
  • 4
0
votes
0 answers

bcadd function not adding correctly

I have a problem in my php code where it didn't sum two floating point numbers. For this below code snippet it shows the output of "0.00108225". print_r(bcadd(0.00108225, 0.00008892,8)); It shows correct output if I add it in a normal way. So is…
0
votes
0 answers

php bcpowmod returns floating point

When using bcpowmod, I sometimes get back a string with a floating point value in it. It only does this sometimes when running the function through WAMP server. Other times, it works as expected, even with the same parameters. If I run the same…
moldstadt
  • 362
  • 2
  • 14
0
votes
0 answers

bcmath calculation doesn't give precise answer

Take a look at this example in regular math:
M. Furqan
  • 31
  • 3
0
votes
1 answer

How get output as integer?

Input will consist of many number pairs, each on a separate line and the numbers are separated by a comma. The numbers can be as big as 100 digits long. The numbers will be integer and factional numbers and negative numbers will not be in input.…
0
votes
1 answer

Decimal multiplication in php

I am having a problem with the multiplication of two decimals 30.63 and 0.15. My calculator says that it should result in 4.60. $commission = bcmul(30.63, 0.15,2); Result from this is 4.59. From what I had read bcmul was meant to work with decimal…
0
votes
2 answers

PHP bcmath needed for whole cent values?

In PHP, I am writing an application which requires precision to 2 digits right of the decimal point for currency (eg: I care about 1.23 === 1.23 but no more right-side digits). I am aware that floats are generally considered bad practice because…
Elly Post
  • 336
  • 3
  • 12
0
votes
1 answer

Why won't bcmath function lose precesion?

We all know that dealing with float point numbers may meet troubles like this: echo intval(0.58*100);//57 And using bcmath functions will help: echo bcmul('0.58', '100', 2);//58.00 php manual: //Multiply the left_operand by the…
luoyu2015
  • 1
  • 2
0
votes
2 answers

How can I get a output with real number of digits in floating point portion from bcdiv function?

The problem is I don't know about the number of digits in floating point part in the output.. I can't assign 4 for example.. there might be 100 digits in floating point for instance n. How can I solve it? bcdiv('50','3',4); //16.6666 …
user3754884
  • 87
  • 11
0
votes
1 answer

bcmath in a shared hosting throught .htaccess

I need to use bcmath in a shared hosting that does not provide it by default. So I asked the hosting company about it and they are not going to provide it. I would have left this hosting as most of the modern hosting provide this and other features…
Abel
  • 538
  • 5
  • 8
  • 28
0
votes
0 answers

CentOS 6.5 - PHP 5.6.7 and bcmath

I am trying to install php-bcmath on CentOS 6.5 and my current PHP Version is 5.6.7. The reason why I'm trying to install this is because I have a plugin for my forum which I am using that throws off errors due to my server using the most recent PHP…
Tyler J
  • 1
  • 1
  • 1
0
votes
0 answers

Using the bcmath functions correctly

I've never used the bcmath figures before and having been doing a bit of reading about comparing and manipulating floating point numbers and this has led me to the bcmath functions. I understand you definitely should use something like the bccomp…
Brett
  • 19,449
  • 54
  • 157
  • 290
0
votes
0 answers

MySQL, using decimal type, still getting imprecise output when using math functions

Have a PHP script - using all the correct bcmath functions, and fully understand the issues with floats. I'm also using decimal columns, because, I was under the impression, those are stored as a different type, and the math is better on those. So I…
0
votes
1 answer

Phpunit and floating point numbers stored as strings

I'm currently using BC Math extension in a project. In my unit tests there are some comparisons that would be similar to the below: This will pass: $this->assertEquals('1.23456789123456789123434', …
Purple Hexagon
  • 3,538
  • 2
  • 24
  • 45