The precise decimal position of the PHP rounding and the method to take the whole

Source: Internet
Author: User
Tags array html page integer sprintf

This article will use PHP to round up the numbers to keep n decimal digits, as well as using PHP for the number of rounding method to do a small sum.

(1) PHP retains three decimal places and rounded

$num =0.0215489;
Echo sprintf ("%.3f", $num); 0.022

(2) PHP keep three decimal digits not rounded

$num =0.0215489;
Echo substr (sprintf ("%.4f", $num), 0,-1); 0.021

(3) php into a method to take an integer (this in the paging program in the number of pages in the program will be used)

echo ceil (4.3);    5
Echo ceil (9.999);  10

(4) The method of the PHP house to take the integer

echo floor (4.3);   4
Echo Floor (9.999);//9

Articles that you may be interested in

    • PHP statistics online numbers, accurate statistics online number of ways
    • Summary of methods for using Curl post submission data and get access to Web page data in PHP
    • PHP's most accurate string length intercept function
    • PHP compressed HTML page code to reduce network data transfer, clear spaces, tabs, comment marks
    • Introduction to the parallel set, intersection and difference set functions of arrays in PHP
    • Powerful PHP Image processing class (watermark, transparency, zoom, sharpen, rotate, flip, cut, invert color)
    • PHP presses the element to the array header (Array_unshift usage)
    • PHP uses Array_flip to implement array key exchange to remove duplicate value of array


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.