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 php converts 2.131 to integers

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

Share

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

This article mainly explains "php how to convert 2.131 into integers", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "php how to convert 2.131 into integers"!

Php converts 2.131 into integers: 1, rounding using floor function; 2, rounding using ceil function; 3, rounding through round function.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php convert 2.131 to integers?

PHP has three ways to convert decimals to integers:

This article mainly introduces three methods of converting decimals to integers by PHP. In fact, it uses three functions of PHP, namely floor, ceil and round. Friends who need them can refer to them.

Float floor (float value) rounding method

Returns the next integer not greater than value, rounding off the fractional portion of value. The type returned by floor () is still float, because the range of float values is usually larger than integer.

The code is as follows:

Echo floor (4.3); / / 4echo floor (9.999); / / 9echo floor (2.131); / / 2

Float ceil (float value) one-way rounding

Returns the next integer not less than value, and value takes one place if it has a decimal part. The type returned by ceil () is still float, because the range of float values is usually larger than integer.

The code is as follows:

Echo ceil (4.3); / / 5echo ceil (9.999); / / 10echo ceil (2.131); / / 3

Float round (float val [, int precision]) rounds floating-point numbers

Returns the result that val is rounded based on the specified precision precision (the number of digits after the decimal point). Precision can also be negative or zero (default).

The code is as follows:

Echo round (2.131); / / 2echo round (3.4); / / 3echo round (3.5); / / 4echo round (3.6); / / 4echo round (3.60); / / 4echo round (1.95583, 2); / / 1.96echo round (1241757,-3); / / 1242000echo round (5.045, 2); / / 5.04echo round (5.055, 2) Thank you for your reading, these are the contents of "how php converts 2.131 into integers". After the study of this article, I believe you have a deeper understanding of how php converts 2.131 into integers, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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