The floor function Problem of PHP

Source: Internet
Author: User
Tags floor function
$money = 271.29;
echo $money =floor ($money *pow (10,2));
This print is 27129

$money = 271.28;
echo $money =floor ($money *pow (10,2));
and the print result is 27127.


Reply to discussion (solution)

$money =271.28;printf ("%.12f", $money *pow (10,2)); 27127.999999999996echo $money =floor ($money *pow (10,2)); 27127

27127.999999999996 is not 27127 after the end of the cut?

$money =271.28;printf ("%.12f", $money *pow (10,2)); 27127.999999999996echo $money =floor ($money *pow (10,2)); 27127

27127.999999999996 is not 27127 after the end of the cut?


Why not 27128.00000000 but 27127.999999999996

Because it is a floating point, there is a natural problem of accuracy.
Please cram your knowledge about floating-point numbers

? in PHP floating??
Can you take a look?? : http://www.laruence.com/2013/03/26/2884.html

http://php.net/manual/zh/function.floor.php
http://php.net/manual/zh/function.ceil.php
http://php.net/manual/zh/function.round.php

  • Related Article

    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.