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
23
votes
6 answers

How to ceil, floor and round bcmath numbers?

I need to mimic the exact functionality of the ceil(), floor() and round() functions on bcmath numbers, I've already found a very similar question but unfortunately the answer provided isn't good enough for me since it lacks support for negative…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
23
votes
15 answers

Is there any Java function or util class which does rounding this way: func(3/2) = 2?

Is there any Java function or util class which does rounding this way: func(3/2) = 2 Math.ceil() doesn't help, which by name should have done so. I am aware of BigDecimal, but don't need it.
Rig Veda
  • 801
  • 2
  • 10
  • 17
22
votes
10 answers

Ceil function: how can we implement it ourselves?

I know that C++ provides us with a ceil function. For practice, I was wondering how can we implement the ceil function in C++. The signature of the method is public static int ceil(float num) Please provide some insight. I thought of a simple way:…
TimeToCodeTheRoad
  • 7,032
  • 16
  • 57
  • 70
22
votes
4 answers

floor and ceil with number of decimals

I need to floor a float number with an specific number of decimals. So: 2.1235 with 2 decimals --> 2.12 2.1276 with 2 decimals --> 2.12 (round would give 2.13 which is not what I need) The function np.round accepts a decimals parameter but it…
user2261062
18
votes
3 answers

How to round up a number if it's not an integer?

I want to calculate a simple number, and if the number is not an integer I want to round it up. For instance, if after a calculation I get 1.2, I want to change it to 2. If the number is 3.7, I want to change it to 4 and so on.
nick shmick
  • 905
  • 1
  • 9
  • 25
16
votes
8 answers

What's the difference between the pair of functions floor()/ceil() and min()/max()?

I would say all programming languages have functions with these names to choose the lesser or greater of two values: min() & max() floor() & ceil() / ceiling() And some languages have both. JavaScript I believe is one example. I've always been a…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
16
votes
6 answers

getting Ceil() of Decimal in python?

Is there a way to get the ceil of a high precision Decimal in python? >>> import decimal; >>> decimal.Decimal(800000000000000000001)/100000000000000000000 Decimal('8.00000000000000000001') >>>…
Gunjan
  • 1,177
  • 2
  • 11
  • 22
16
votes
2 answers

Ceiling of a number in JSTL/EL

In JSTL, returns 2 and the following returns1 and I need 2, a ceiling of a number. Is there a direct way to achieve this in…
Tiny
  • 27,221
  • 105
  • 339
  • 599
12
votes
2 answers

javascript - ceiling of a dollar amount

So I am adding and subtracting floats in javascript, and I need to know how to always take the ceiling of any number that has more than 3 decimal places. For example: 3.19 = 3.19 3.191 = 3.20 3.00000001 = 3.01
bmarti44
  • 1,247
  • 2
  • 14
  • 22
11
votes
3 answers

Excel-like ceiling function in python?

I know about math.ceil and numpy.ceil, but both of them lack of significance parameter. For example in Excel: =Ceiling(210.63, 0.05) -> 210.65 numpy.ceil and math.ceil in other hand: numpy.ceil(210.63) -> 211.0 math.ceil(210.63) -> 211.0 So, I…
Vladimiroff
  • 473
  • 4
  • 11
11
votes
3 answers

Why does Binary search algorithm use floor and not ceiling - not in an half open range

When we have an array with indexes from 0 to n for example. when I use the Binary search using floor or ceiling when calculating the middle index I get the same out put. int middle = ceiling ((left+right)/2); Is there a reason using floor over…
tal
  • 179
  • 1
  • 2
  • 7
11
votes
4 answers

Getting the ceil value of a number in SQLite

So I see this question has a good answer, but I want to round up no matter what, instead of rounding down no matter what. Adding 1 to it before casting int wouldn't work because it would "round" 5.0 into 6.0, for example. So how should I implement…
wrongusername
  • 18,564
  • 40
  • 130
  • 214
10
votes
7 answers

C# Math.Ceiling bug or not?

I do not know why Ceiling behave like in the below image Why is processingFee != Settings.PaymentProcessingFeeInPercentage * prizesSum ? View image at full size alt text http://img514.imageshack.us/img514/3950/csharpceilingproblem.png
Sorin
  • 2,258
  • 4
  • 27
  • 45
10
votes
3 answers

Why is Math.ceil not rounding upwards?

I have the following code: int total = 6; int perPage = 5; double pages = total/perPage; double ceilPages = Math.ceil(pages); out.println(ceilPages); Which outputs 1.0. I thought it should output 2.0 because the result of total/perPage is 1.2. Why…
crmepham
  • 4,676
  • 19
  • 80
  • 155
9
votes
3 answers

CEIL and FLOOR in SQLite

What is the cleanest method to find the ciel and floor of a number in SQLite? Unfortunately SQLite only has ROUND() function.
Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
1
2
3
20 21