Questions tagged [ceil]

A function common to many programming languages that returns the next integer value by rounding the value up if necessary.

Returns the next highest integer value by rounding up value if necessary. php.net

Examples

echo ceil(1.3);    // returns   2
echo ceil(10.9);   // returns  11
echo ceil(-3.14);  // returns  -3
301 questions
3
votes
2 answers

Ambiguous reference to member when using ceil or round

I am just trying to use the ceil or round functions in Swift but am getting a compile time error: Ambiguous reference to member 'ceil'. I have already imported the Foundation and UIKit modules. I have tried to compile it with and without the…
neena
  • 365
  • 1
  • 6
  • 22
3
votes
2 answers

Why floor(0.99999999999999999) = 1 and floor(0.9999999999999999) = 0?

floor function in PHP behave weirdly. For 16 decimal values it gives floor value but by increasing 1 decimal it round. $int = 0.99999999999999999; echo floor($int); // returns 1 $int = 0.9999999999999999; echo floor($int); // returns 0 $int =…
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
3
votes
2 answers

Use of Ceil and Integers

So I just got my grade back from a school project that I did well on, but the grader took five points off because I didn't make a call to ceil(...). Its a parallel computing course using CUDA, but the question isn't directly related to any CUDA…
csnate
  • 1,601
  • 4
  • 19
  • 31
3
votes
6 answers

Unexpected result using POSIX ceil() in Perl

I can't for the life of me figure out why the following produces the result it does. use POSIX; my $g = 6.65; my $t = $g * 4; my $r = $t - $g; my $n = $r / $g; my $c = ceil($n); print "$c ($n)\n"; Sigil-tastic, I know — sorry. I've solved this for…
shedside
  • 61
  • 1
  • 6
3
votes
4 answers

ceil() and floor() functions in C++ for size_t types

I have two variables: size_t a = 63; size_t b = 32; I called the function ceil(a/b). Naturally I would assume that the answer returns 2 but instead it returns 1. I'm puzzled. I have tried casting the variables to a double or int and it doesn't…
user2588659
  • 43
  • 1
  • 3
3
votes
3 answers

Implementing ceil function without using if-else

I just wanted to know that is there a way of implementing ceil function without using if-else? With if-else (for a/b) it can be implemented as: if a%b == 0: return(a/b) else: return(a//b + 1)
Ankur Ankan
  • 2,953
  • 2
  • 23
  • 38
3
votes
3 answers

CEIL is one too high for exact integer divisions

This morning I lost a bunch of files, but because the volume they were one was both internally and externally defragmented, all of the information necessary for a 100% recovery is available; I just need to fill in the FAT where required. I wrote a…
Synetech
  • 9,643
  • 9
  • 64
  • 96
2
votes
3 answers

Fractional Part of the number question

What is a good algorithm to determine the necessary fraction needed to add/sub to the number in order to round it to the nearest integer without using the inbuilt ceiling or floor funcitons? Edit: Looking for a mathematical number trick to figure…
unj2
  • 52,135
  • 87
  • 247
  • 375
2
votes
2 answers

php round up / ceil merge mysql AVG()

or Show Average i have this : $item = mysql_query("SELECT AVG(top) AS total FROM " . "$config_ccms_prefix" . "news where id='$id'"); while ($cms = mysql_fetch_assoc($item)) { $avg = ceil(($cms[total]),0.5); } //...... example…
Saimon Avazian
  • 281
  • 2
  • 6
  • 18
2
votes
1 answer

PHP ceil returning a float

I've created a function to return the difference between two dates
SmootQ
  • 2,096
  • 7
  • 33
  • 58
2
votes
2 answers

Customized floor/ceiling for dates in R

say I have a date range from start to end where start <- as.Date(2009-11-05), end <- as.Date(2009-12-17). I want a function that essentially acts as a customized floor/ceiling and returns a date interval such that the lower bound is the first date…
Algebro1000
  • 161
  • 9
2
votes
2 answers

How ceil function works in c++?

When I execute this code the value of ans1, ans2 is 50002896 and 50005000. I know there is some issues with ceil function but was not able to figure out the exact cause. #include using namespace std; int main() { long long ans1…
Chinnmay B S
  • 77
  • 1
  • 5
2
votes
1 answer

Problem with ceil function in math module

by performing the following calculation p=math.ceil(57050*1.12) I am receiving 63897. However other tools (such as Excel) deliver 63896. I need to use ceil (round up), because the procedure is part of a larger model, where I cannot make an exeption…
ZetDen
  • 155
  • 8
2
votes
4 answers

php: round minutes up to the nearest quarter hour, then do more

The initial problem is this: Take the amount of minutes -> turn into quarter hours -> 1 quarter hour is 1 unit -> output units I've been putting a page together all day today and my brain just stopped working a couple of minutes ago and I just…
mikepreble
  • 269
  • 2
  • 5
  • 17
2
votes
4 answers

PHP calculate integer of division

I would like to calculate an integer part of division. The numerator and denominator (especially their precision) should not be altered because it might change from one calculation to other, also the denominator is as an example, its integer part as…
Jimmix
  • 5,644
  • 6
  • 44
  • 71