• 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. PHP asin function – Arc sine
  2. PHP function chunk_split() – Split a string into smaller chunks
  3. PHP function acos – Arc cosine
  4. PHP Function strchr() – Alias of strstr()
  5. PHP function convert_cyr_string() – Convert from one Cyrillic character set to another
  6. PHP atan function – Arc tangent
  7. PHP base_convert function – Convert a number between arbitrary bases
  8. PHP Function str_split() – Convert a string to an array
  9. PHP function chr() – Generate a single-byte string from a number
  10. PHP function str_replace() – Replace all occurrences of the search string with the replacement string

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright