PHP has a different approach to floating-point data

Source: Internet
Author: User
Tags php code square root

Php:bcmath

BC is the abbreviation of binary calculator. The arguments for the bc* function are the operands plus an optional [int scale], such as String Bcadd (String $left _operand, String $right _operand[, int $scale]), if scale does not provide , the default value of Bcscale is used. The large number is directly represented by a string of 0-9, and the result returns a string.

Bcadd-adds two high precision numbers

bccomp-compares two high-precision digits, returns-1, 0, 1

bcdiv-divides two high-precision digits

bcmod-to find high precision digit remainder

Bcmul-multiplies two high precision numbers

bcpow-to find high precision digital exponentiation

Bcpowmod-to seek high-precision digital exponentiation, the number theory is very common

bcscale-Configure the default decimal point number, which is equivalent to the "scale=" in Linux BC

bcsqrt-High precision Digital square root

bcsub-subtracts two high-precision digits

You can refer to the manual to find out the application of these functions.

PHP code?

/*bcsub function Description

This function subtracts two highly-accurate numbers, passes in two strings, and subtracts the right operand value from the left operand. Scale is an optional option that represents the number of digits required after the  decimal point of the returned value. */

The following code I was guaranteed a decimal point digit

$aa =bcsub (134.7,52.5,1);

echo $aa;//exit;

$BB =bcsub ($aa, 82.2, 1);

echo $bb;//exit;

You can try it out.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.