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

What are the differences between float and double in php

2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this article "what are the differences between float and double in php", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the difference between float and double in php".

In PHP, there is no difference between float and double. Floating-point types in PHP are also called floating-point float, double-precision double, or real real,float, double, or real are the same data types and can be defined using the same syntax.

Operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer

What is the difference between float and double in php

To distinguish the difference between float and double in php, I use the following code to output respectively.

$vad = 1.1 th print gettype ($vad); var_dump ($vad)

This will output:

Doublefloat (1.1)

It looks different, but in fact, in php, there is no difference. Float,double or real are the same data type. Floating point type (also known as floating point float, double precision double or real real. At level C, everything is stored in pairs.

The accuracy of floating point numbers

The precision of floating point numbers is limited. Although PHP usually uses the IEEE 754 double-precision format depending on the system, the maximum relative error caused by rounding is 1.11e-16. Non-basic mathematical operations may give larger errors, and the error transfer in composite operations should be taken into account.

In addition, rational numbers that can be accurately represented in decimal, such as 0.1 or 0.7, no matter how many Mantissa are, cannot be accurately represented by the binary used internally, so they cannot be converted to a binary format without losing a little bit of precision. This can lead to confusing results: for example, floor ((0.1-0.7) * 10) usually returns 7 instead of the expected 8, because the internal representation of the result is actually similar to 7.99999999999991118.

So never believe that floating-point results are accurate to the last digit, and never compare whether two floating-point numbers are equal. If you do need higher precision, you should use any precision mathematical function or gmp function.

The above is about the content of this article on "what is the difference between float and double in php?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

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