PHP floor function problem.
I am currently writing a project about finance. There are a lot of decimal issues involved. Once when I used floor to round down to two decimal places, I suddenly found that the following code was abnormal.
$money=271.28; echo $money=floor($money*pow(10,2))/100
Later I checked a lot of information and saw this on the php official website:
Later I printed the result of the above operation:
printf("%.12f", $money*pow(10,2));
It turned out to be an accuracy problem. No unified solution has been found yet. I can only add
if ($money - round ( $money, 2 ) < 0.00001) { }else{ $money=floor($money*pow(10,2))/100; }
If anyone knows another way to implement the above function (accurate to two decimal places and discard whatever the third digit is), please let me know.
The above introduces the problem of PHP's floor function. , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to use MySQL's FLOOR function to round down In MySQL, the FLOOR function is used to round down. The FLOOR function is a very useful tool if you need to round down a floating point number or a number with a decimal point to the nearest integer. This article will introduce how to use MySQL's FLOOR function and provide some practical example code. First, let's understand the syntax of the FLOOR function. The syntax of the FLOOR function is as follows: FLOOR(x) where x represents

Use Java's Math.pow() function to calculate the power of a numerical value. In mathematical operations, we often need to calculate the power of a numerical value. In Java, we can use the Math.pow() function to perform exponentiation operations. This article will introduce how to use the Math.pow() function and give some code examples. The Math.pow() function is a static method in the mathematics library in Java, used to calculate the power of a value and return the calculation result. Its syntax is as follows: Math.p

This article takes an in-depth look at two mainstream consensus mechanisms: Proof of Stake (PoS) and Proof of Work (PoW). PoS requires validators to pledge tokens to obtain the power to verify transactions. It has the advantages of energy saving and good scalability, but it may also lead to concentration of wealth. PoW requires miners to solve complex mathematical problems to verify transactions. It is more secure and decentralized, but it consumes a lot of energy and has poor scalability. This article compares the principles, advantages and disadvantages, and applications of PoS and PoW in the blockchain field to help readers understand the key roles they play in the consensus mechanism.

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。

图片消失如何解决先是图片文件上传$file=$_FILES['userfile']; if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'

图片消失如何解决先是图片文件上传$file=$_FILES['userfile']; if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'
