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
114
votes
5 answers

Floor or ceiling of a pandas series in python?

I have a pandas series series. If I want to get the element-wise floor or ceiling, is there a built in method or do I have to write the function and use apply? I ask because the data is big so I appreciate efficiency. Also this question has not…
wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
102
votes
7 answers

Round up a CGFloat in Swift

How can I round up a CGFloat in Swift? I've tried ceil(CDouble(myCGFloat)) but that only works on iPad Air & iPhone 5S. When running on another simulated device I get an error saying 'NSNumber' is not a subtype of 'CGFloat'
Oskar Persson
  • 6,605
  • 15
  • 63
  • 124
81
votes
2 answers

Why does Math.ceil return a double?

When I call Math.ceil(5.2) the return is the double 6.0. My natural inclination was to think that Math.ceil(double a) would return a long. From the documentation: ceil(double a) Returns the smallest (closest to negative infinity) double value …
PengOne
  • 48,188
  • 17
  • 130
  • 149
59
votes
16 answers

Get ceiling integer from number in linux (BASH)

How would I do something like: ceiling(N/500) N representing a number. But in a linux Bash script
Mint
  • 14,388
  • 30
  • 76
  • 108
52
votes
7 answers

Python round to next highest power of 10

How would I manage to perform math.ceil such that a number is assigned to the next highest power of 10? # 0.04 -> 0.1 # 0.7 -> 1 # 1.1 -> 10 # 90 -> 100 # ... My current solution is a dictionary that checks the range of the input…
offeltoffel
  • 2,691
  • 2
  • 21
  • 35
52
votes
5 answers

Why Math.Ceiling returns double?

In C# the method Math.Ceiling returns a double value. Why does it not return int?
MaciejLisCK
  • 3,706
  • 5
  • 32
  • 39
50
votes
2 answers

Rounding up to the second decimal place

Possible Duplicate: PHP Round function - round up to 2 dp? What my problem is: When i use ceil(3.6451895227869); i get like 4 but i want 3.65 Can you help me out? UPDATE Please remember: This should always round to ceil like while…
LIGHT
  • 5,604
  • 10
  • 35
  • 78
49
votes
3 answers

Round minutes to ceiling using Java 8

So I'm lucky enough to use Java 8 and the new time APi but I don't see any rounding functions... Basically if the time is... 2014-08-28T10:01.00.000 ----> 2014-08-28T10:02.00.000 2014-08-28T10:01.10.123 ---->…
user432024
  • 4,392
  • 8
  • 49
  • 85
46
votes
4 answers

Rounding to nearest fraction (half, quarter, etc.)

So, I need to create the following functions but my head can't think of any possibility in PHP without complicated math. Round always up to the nearest decimal (1.81 = 1.90, 1.89 = 1.90, 1.85 = 1.90) Round always down to the nearest decimal (1.81 =…
user1649331
33
votes
5 answers

How can I make sure a float will always be rounded up with PHP?

I want to make sure a float in PHP is rounded up if any decimal is present, without worrying about mathematical rounding rules. This function would work as follows: 1.1 to 2 1.2 to 2 1.9 to 2 2.3 to 3 2.8 to 3 I know the round() function exists but…
Sotiris
  • 38,986
  • 11
  • 53
  • 85
33
votes
1 answer

Ruby .ceil and .floor

I'm new to Ruby and I'm trying to figure out how ceil and floor works as I get different answers when a fraction or a decimal number is used (similar value). Below is what I have tried: puts 8/3.ceil == 2 #=> true puts 8/3.floor == 2 #=>…
misokuan
  • 333
  • 1
  • 3
  • 6
31
votes
7 answers

C++ round a double up to 2 decimal places

I am having trouble rounding a GPA double to 2 decimal places. (ex of a GPA needed to be rounded: 3.67924) I am currently using ceil to round up, but it currently outputs it as a whole number (368) here is what I have right now if (cin >> gpa) { …
Bryce Hahn
  • 1,585
  • 4
  • 16
  • 26
29
votes
4 answers

golang - ceil function like php?

I want to return the least integer value greater than or equal to integer division. So I used math.ceil, but can not get the value I want. package main import ( "fmt" "math" ) func main() { var pagesize int = 10 var length int =…
leiyonglin
  • 6,474
  • 12
  • 36
  • 41
28
votes
5 answers

Rounding up and down a number C++

I'm trying to allow my program to round a number up and down respectively. For example, if the number is 3.6, my program is suppose to round up the nearest number which is 4 and if the number is 3.4, it will be rounded down to 3. I tried using the…
Bryan
  • 8,488
  • 14
  • 52
  • 78
24
votes
7 answers

Ceil a datetime to next quarter of an hour

Let's imagine this datetime >>> import datetime >>> dt = datetime.datetime(2012, 10, 25, 17, 32, 16) I'd like to ceil it to the next quarter of hour, in order to get datetime.datetime(2012, 10, 25, 17, 45) I imagine something like >>> quarter =…
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
1
2 3
20 21