Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does PHP deal with floating-point data

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how PHP handles floating point data". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to handle these situations! I hope you can read carefully and learn something!

Php: BCMath

BC is an abbreviation for Binary Calculator. The arguments to the bc* function are operands plus an optional [int scale], such as string bcadd(string $left_operand, string $right_operand[, int $scale]), or the default value of bcscale if scale is not provided. Here, the large number is directly represented by a string composed of 0-9, and the calculation result is also a string.

bcadd -adds two high-precision numbers

bccomp -Compares two high-precision numbers and returns-1, 0, 1

bcdiv -Divides two high-precision numbers

bcmod -Find high-precision digital remainder

bcmul -Multiply two high-precision numbers

bcpow -Power a number with high precision

bcpowmod -High precision number multiplication modulo, very common in number theory

bcscale -Configure the default decimal places, equivalent to "scale=" in Linux bc

bcsqrt -Find the square root of a number with high precision

bcsub -Subtract two high-precision numbers

You can refer to the manual for applications of these functions.

The copy code is as follows:

/*bcsub function description

This function subtracts two high-precision numbers, passing in two strings, subtracting the right operand from the left operand. scale is an optional option that indicates the number of digits required after the decimal point of the return value. */

//The code below is guaranteed to have one decimal place

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

echo $aa;//exit;

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

echo $bb;//exit;

//Floor

"PHP how to handle floating point data" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report