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
4
votes
4 answers

Implementation of ceil function in C

I have two questions regarding ceil() function.. The ceil() function is implemented in C. If I use ceil(3/2), it works fine. But when I use ceil(count/2), if value of count is 3, then it gives compile time error. /tmp/ccA4Yj7p.o(.text+0x364): In…
AGeek
  • 5,165
  • 16
  • 56
  • 72
4
votes
5 answers

Why is math.pow not natively able to deal with ints? (floor/ceil, too)

I know that in Java (and probably other languages), Math.pow is defined on doubles and returns a double. I'm wondering why on earth the folks who wrote Java didn't also write an int-returning pow(int, int) method, which seems to this…
Katie Byers
  • 822
  • 8
  • 16
4
votes
6 answers

Need the nearest integer value in javascript

In my javascript pagination file I was calculating number of pages by Math.ceil() var total_pages = Math.ceil(total_items/items_per_page); But here I am getting 3 for 2.25, 1 for 0.588, 2 for 1.01 etc. But i need to get 2 for 2.25 and 1 for…
Nidheesh
  • 4,390
  • 29
  • 87
  • 150
4
votes
1 answer

SAS: Ceil a time format variable

Is it possible to use the command ceil on a time format variable such as 09:31:23? I would like to use ceil to have 09:32:00. I tried to use something similar to round(time,'0:01:00'T) but I want to use ceil since I don't want to round. Use the…
Plug4
  • 3,838
  • 9
  • 51
  • 79
4
votes
1 answer

ceiling and floor in TreeMap java

I found myself using a TreeMap simply because I needed the capability of looking something up with the floorEntry() (and ceilingEntry()) methods. This obviously make the code a bit clumsy. So does anyone happen to know if there is any built-in…
user113454
  • 2,273
  • 9
  • 28
  • 35
3
votes
1 answer

Rounding up a number to two decimal places in c++

I'm wishing to round up a float variable to two decimal places regardless of what the float is. My current code is shown below: void MainMethods::convert(float& floatValue, string numericString) { floatValue = stof(numericString); //converts…
3
votes
2 answers

Floor or Ceiling away from zero in Python

Using Python 3, is there a more Pythonic way to floor/ceil as float away from zero than doing this: import math def away_from_zero(x): if x > 0: return int(math.ceil(x)) else: return int(math.floor(x)) Is there a better…
XYZT
  • 605
  • 5
  • 17
3
votes
1 answer

Assembly Language equivalent to Ceil , Floor

What is the x86 equivalent of ceil , floor ? I can't particularly google the corresponding instructions . The equivalent may not necessarily be a one instruction though one instruction would be preferred.
Apoorv Jain
  • 113
  • 9
3
votes
1 answer

Java - Misunderstand ceil and floor methods

floor: Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. ... ceil: Returns the smallest (closest to negative infinity) double value that is greater…
3
votes
2 answers

Ceiling function in R is inaccurate (sometimes)

I am trying to round up a number x to be divisible by a number m. Using the following function from previous post on SO: roundUP = function(x,m) { return(m * ceiling(x/m)) } But, when I input x = 0.28 and m = 0.005, the function outputs 0.285…
Khiem Nguyen
  • 129
  • 1
  • 11
3
votes
3 answers

How exactly NavigableMap.ceiling Entry() work?

I don't understand how NavigableMap.floorEntry() and ceiling Entry() work. Oracle simply writes about ceilingEntry(key): Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no…
Code Complete
  • 3,146
  • 1
  • 15
  • 38
3
votes
1 answer

Math.ceil(00.1); Uncaught SyntaxError: missing ) after argument list

I was debugging on chrome console and found this error. Basically, Math.ceil(0.1); // Works Math.ceil(00.1); // Doesn't work Any reason / thoughts for this? Thanks.
Tpn Knvl
  • 43
  • 4
3
votes
2 answers

Minutes to hours in decimal + round in C#

I'm trying to convert minutes to hours in decimal and round to the nearest fifteen minutes (rounded up). Basically: 15 minutes = 0.25 hour 25 minutes = 0.5 hour 30 minutes = 0.5 hour 50 minutes = 1 hour 60 minutes = 1 hour I haven't found anything…
Kahn Kah
  • 1,389
  • 7
  • 24
  • 49
3
votes
2 answers

Next integer greater than but not equal to input

Is there a (Matlab) function similar to ceil to find the next integer that is greater than the input but not equal to the input? Examples: 1.1 --> 2 1.9 --> 2 2.0 --> 3 (note that ceil(2) == 2) 2.1 --> 3 I tried with ceil(x+eps), but that only…
Laurenz
  • 1,810
  • 12
  • 25
3
votes
2 answers

ceil function doesn't return what it should

I have a problem with the ceil function in matlab. When I say "ceil(192.00)" it returns 192, as it should. However, when I declare a variable x and assign it 14*(256/20)+(256/20), that being exactly 192.00, ceil(x) returns 193. Why is that? Thanks…
Vlad Iordache
  • 468
  • 1
  • 5
  • 16