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
9
votes
2 answers

Strange working of ceil() function (php)

This code: echo (40 * (10 / 100 + 1)); //44 echo (50 * (10 / 100 + 1)); //55 echo ceil(40 * ((10 / 100) + 1)); //44 echo ceil(50 * ((10 / 100) + 1)); //56 (!) I think, that "56" by reason of floating point (55.0000000001 => 56), but I can't…
9
votes
4 answers

How to get array_walk working with PHP built in functions?

I just want to use array_walk() with ceil() to round all the elements within an array. But it doesn't work. The code: $numbs = array(3, 5.5, -10.5); array_walk($numbs, "ceil"); print_r($numbs); output should be: 3,6,-10 The error message: …
user4479187
8
votes
1 answer

Julia: Can ceil/floor return an integer?

Why don't ceil() and floor() return an integer? How can I return an integer? a = 10 b = 3 typeof(a/b) ## Float64 c = ceil(a/b) typeof(c) ## Float64 This issue bothered me in the context of calculating a range, e.g. k = 0:1:c ##…
PatrickT
  • 10,037
  • 9
  • 76
  • 111
8
votes
1 answer

floor() and ceil() functions vs casting to integer in C

I am writing some C code to repeatedly round floats up and down to integer values. The standard C math library includes the functions floor() and ceil(). I noticed that a much quicker implementation of the functions is to cast directly to…
samuelschaefer
  • 614
  • 2
  • 10
  • 26
8
votes
3 answers

CEILING returns FLOOR result - SQL SERVER 2008 R2

DECLARE @a int; DECLARE @b int; SET @a = 9; SET @b = 2; SELECT CEILING (@a/@b); It is returning as 4 instead of 5. Why? Edit: I would like to get next smallest integer if the quotient is not whole number.
Gopi
  • 5,656
  • 22
  • 80
  • 146
7
votes
3 answers

Strange results with C++ ceiling function

I've been trying the ceiling function and have been getting some strange results. If I perform the ceil operation on a decimal number multiplied by hundred I get a certain result. However if i directly perform ceil on the result of that…
sowmya
  • 221
  • 1
  • 3
  • 5
7
votes
2 answers

Is it safe to cast result of ceil to integer?

ceil function in C is declared as double ceil(double). Is it safe to cast return value of the function to int? I mean is there any guarantee that the following will never occur (the sample is just to illustrate of what I mean)? double r =…
Nick
  • 3,205
  • 9
  • 57
  • 108
7
votes
1 answer

Representable result of floor() and ceil()

For an arbitrary value 'v' of a floating point type (float/double/long double), does C89 guarantee that the mathematically exact integer result of floor(v) and ceil(v) is a representable value of the type of 'v'? Does any of the later C or C++…
Kristian Spangsege
  • 2,903
  • 1
  • 20
  • 43
7
votes
6 answers

Understanding CEILING macro use cases

I've found the following macro in a utility header in our codebase: #define CEILING(x,y) (((x) + (y) - 1) / (y)) Which (with help from this answer) I've parsed as: // Return the smallest multiple N of y such that: // x <= y * N But, no matter…
tdenniston
  • 3,389
  • 2
  • 21
  • 29
6
votes
5 answers

C++ ceil and negative zero

On VC++ 2008, ceil(-0.5) is returning -0.0. Is this usual/expected behavior? What is the best practice to avoid printing a -0.0 to i/o streams.
ThomasMcLeod
  • 7,603
  • 4
  • 42
  • 80
6
votes
1 answer

round,ceiling 2 decimal points

I want to round up some figures that have 2 decimals points to 1. However, I always want it to round 1 examples of the list of figures in column amount 140.08 = 140.1 141.63 = 141.7 if I use round(141.63,1) it equals 142.6, but I want all the…
Don Mercer
  • 67
  • 1
  • 1
  • 4
6
votes
1 answer

Swift equivalent of ceilf for CGFloat

I was trying to do something like this var myCGFloat: CGFloat = 3.001 ceilf(myCGFloat) but ceilf only takes Float values. While searching around there were lots of different answers about doing this conversion or that depending on whether it is 32…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
6
votes
1 answer

How to use sqrt and ceil with Boost::multiprecision?

Do you know how to do this simple line of code without error using Boost::multiprecison ? boost::multiprecision::cpp_int v, uMax, candidate; //... v += 6 * ceil((sqrt(uMax * uMax - candidate) - v) / 6); Using MSVC there is an error for "sqrt" and…
6
votes
3 answers

VLOOKUP not finding value in array

I used VLOOKUP function to find a value in an array but some of the values gave #N/A answer despite of available in array. To round up the numbers, I used CEILING function but interesting point is in some values, it did not work. I checked the type…
render ly
  • 63
  • 5
6
votes
1 answer

Javascript ceil with 2 decimal places instead of 1

I have a bit of javascript that's working well for me, I'd just like it to keep 2 decimal places instead of hiding the extra decimal place if its 0. Right now it says: "0.2" and I'd like it to say: "0.20" Here's the Javascript. Can anyone please…
ihateartists
  • 328
  • 4
  • 17
1 2
3
20 21