PHP requires different solutions for floating point data _ php instance

Source: Internet
Author: User
This article mainly introduces how to solve floating point data in PHP in different ways. For more information, see. Php: BCMath

Bc is short for Binary Calculator. Bc * function parameters are all operands plus an optional [int scale], such as string bcadd (string $ left_operand, string $ right_operand [, int $ scale]). If scale is not provided, use the default value of bcscale. Here, the large number is represented by a string consisting of 0-9, and the return value is also a string.

Bcadd-add two high-precision numbers
Bccomp-compare two high-precision numbers and return-1, 0, 1
Bcp-division of two high-precision numbers
Bcmod-precise digital Remainder
Bcmul-multiply two high-precision numbers
Bcpow-calculate a high-precision digital Multiplier
Bcpowmod-modulus of high-precision multiplication of numbers, which is very common in number theory.
Bcscale-the default number of decimal places configured, which is equivalent to "scale =" in Linux bc"
Bcsqrt-calculate the square root of a precise number
Bcsub-Subtract two high-precision numbers

You can refer to the Manual to check the application of these functions.

The Code is as follows:


/* Bcsub Function Description
This function subtract two high-precision numbers and input two strings, minus the right operand value on the left. Scale is an optional option, indicating the number of digits required after the decimal point of the returned value. */
// The following Code ensures that the decimal point is one digit.
$ Aa = bcsub (134.7, 52.5, 1 );
Echo $ aa; // exit;
$ Bb = bcsub ($ aa, 82.2, 1 );
Echo $ bb; // exit;
// Floor

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.