• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP ceil function – Round fractions up

by admin

Description

Returns an integer that is the next larger than the float used as the argument. In essence, it rounds up a floating-point number to an integer, no matter what the value of the floating-point integer is. It doesn’t round down.

Syntax:

ceil(int|float $num): float

The ceil() function takes a floating-point number as its only parameter and rounds it to the nearest integer above its current value. If you provide an integer, nothing will happen. For example:

$number = ceil(11.9); // 12
$number = ceil(11.1); // 12
$number = ceil(11); // 11

Parameters

Parameter Description
num The value to round.

Return Values

num rounded up to the next highest integer. The return value of ceil() is still of type float as the value range of float is usually bigger than that of int.

Examples

Example 1: Round up a floating-point number:

$number = 12.023; 
echo "The next highest integer of $number is ", ceil($number);

Example 2:

echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3

Filed Under: PHP

Some more articles you might also be interested in …

  1. htaccess Cheatsheet
  2. PHP function abs – Absolute value
  3. PHP atanh function – Inverse hyperbolic tangent
  4. PHP function strcasecmp() – Binary safe case-insensitive string comparison
  5. How to test a PHP script
  6. PHP function strlen() – Get string length
  7. PHP atan function – Arc tangent
  8. PHP function chunk_split() – Split a string into smaller chunks
  9. PHP function str_replace() – Replace all occurrences of the search string with the replacement string
  10. PHP atan2 function – Arc tangent of two variables

You May Also Like

Primary Sidebar

Recent Posts

  • ctags: Generates an index (or tag) file of language objects found in source files for many popular programming languages
  • csvtool: Utility to filter and extract data from CSV formatted sources
  • csvstat: Print descriptive statistics for all columns in a CSV file
  • csvsql: Generate SQL statements for a CSV file or execute those statements directly on a database

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright