The functions ceil() and floor() will return different numbers than what you get by using

up = (int)(test + 1);
down  = (int)test;

when you have a negative number.

If you have:

float test = -1.3548;
up = (int)test;        // ceil()
down = (int)(test-1);  // floor()

Even the last statement is not a good way to compute floor() when test is an integral number.

Unless you want to deal with positive and negative numbers differently, and the special cases of when test is integral number, you are better off using ceil() and floor().

Answer from R Sahu on Stack Overflow
🌐
Sololearn
sololearn.com › en › Discuss › 2672320 › i-am-confused-between-floor-ceil-and-round-functions-in-c-programming-could-you-please-explain-it-down-here-
I am confused between floor(), ceil() and round() functions in C Programming. Could you please explain it down here? 🙏🥺 | Sololearn: Learn to code for FREE!
FLOOR - To get the floor, just remove the decimal next to it. (round down) 2.8 --> 2 CEIL - To get the ceil, just remove the decimal next to it then add 1 (round up) 2.2 --> 3 For negative numbers, just do the opposite.
🌐
W3Schools
w3schools.com › c › ref_math_ceil.php
C Math ceil() Function
C Examples C Real-Life Examples ... function is defined in the <math.h> header file. Tip: To round a number DOWN to the nearest integer, look at the floor() function....
Discussions

Floor and ceil function - Post.Byes - Bytes
I've learned that we can round ... by using Ceil and floor function. But, is this function still able to work if I the number I want to round up (or down) is zero? I have wrote my codes, but somehow it didn't give the right answer if the number is zero. My simple code looks like this: ... #include int ... More on post.bytes.com
🌐 post.bytes.com
May 26, 2009
Looking for a kind soul to assist with 'floor' and 'ceil' in C++
You need to debug your code and see the variable values. If you are unable to use debugger, use debug prints. I mean, how do you know floor and ceil work wrong? Maybe they work exactly right, and bug is elsewhere. More on reddit.com
🌐 r/cpp_questions
8
1
December 8, 2022
Programming FLOOR & CEIL
Which HP do you have? The 28, 48, 49, 50, and Prime series all have CEIL, FLOOR, and RND. More on reddit.com
🌐 r/calculators
27
May 19, 2024
Flooring and ceiling integers in C
Integer division is truncated towards 0 in C99 and newer, and rounded in an implementation defined direction in older versions of the standard. More on reddit.com
🌐 r/learnprogramming
13
1
December 7, 2018
People also ask

How do you use ceil and floor?
The floor and ceiling functions round a decimal number to the nearest integer. For instance, the floor and ceiling of 3.31, respectively, are 3 and 4. This allows us to locate the closest integer to a decimal number on a number line.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
What is the ceil() function in C?
The ceil() function in C is a math function used to round any floating-point number up to the nearest integer. It is available in the math.h library and returns a double value.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
What is floor () vs ceil ()?
The Math.ceil method provides the smallest integer as a result, which is higher than or equals the given value, while Math.floor offers the largest integer as a result that is less than or equal to the provided value. In simple terms, floor() rounds down while ceil () rounds up to the closest integer value.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
🌐
Programiz
programiz.com › c-programming › library-function › math.h › ceil
C ceil() - C Standard Library
Check odd/even number · Find roots ... C sinh() C log() C log10() C tanh() C floor() double ceil( double arg ); The ceil() function takes a single argument and returns the nearest integer number....
🌐
IncludeHelp
includehelp.com › c-programs › c-basic-programs-to-demonstrate-example-of-floor-and-ceil-functions.aspx
Example of floor() and ceil() functions in c
Both functions are library functions and declare in math.h header file. /* C program to demonstrate example of floor and ceil functions.*/ #include <stdio.h> #include <math.h> int main() { float val; float fVal,cVal; printf("Enter a float value: "); scanf("%f",&val); fVal=floor(val); cVal =ceil(val); printf("floor value:%f \nceil value:%f\n",fVal,cVal); return 0; }
🌐
Sanfoundry
sanfoundry.com › c-tutorials-floor-ceiling-absolute-value-remainder-functions-standard-library
floor(), ceil(), fabs() and fmod() Functions in C - Sanfoundry
December 31, 2025 - The ceil() function returns the smallest integer value greater than or equal to the given number.
Find elsewhere
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
January 4, 2026 - The ceil() function calculates the next highest whole number greater than or equal to x. The floor and ceiling functions round a decimal number to the nearest integer. For instance, the floor and ceiling of 3.31, respectively, are 3 and 4.
🌐
TutorialsPoint
tutorialspoint.com › c_standard_library › c_function_ceil.htm
C library - ceil() function
#include <stdio.h> #include <math.h> int main() { double start = 1.5; double end = 10.5; printf("Table of Ceiling Integers:\n"); for (double num = start; num <= end; num += 1.0) { int result = ceil(num); printf("Ceil(%.2lf) = %d\n", num, result); } return 0; } After executing the code, we get the following result −
🌐
Medium
medium.com › @ryan_forrester_ › floor-and-ceil-functions-in-c-complete-guide-89358b364ce0
Floor and Ceil Functions in C++: Complete Guide | by ryan | Medium
October 22, 2024 - Here’s how to use `floor()` and `ceil()` for financial rounding: class MoneyCalculator { public: // Round to nearest cent static double round_currency(double amount) { return std::floor(amount * 100 + 0.5) / 100; } // Round up to nearest cent (e.g., for fees) static double ceil_currency(double amount) { return std::ceil(amount * 100) / 100; } // Round down to nearest cent (e.g., for discounts) static double floor_currency(double amount) { return std::floor(amount * 100) / 100; } }; void financial_example() { double price = 19.999; double tax_rate = 0.08; // 8% tax double tax = MoneyCalculator::ceil_currency(price * tax_rate); double final_price = MoneyCalculator::round_currency(price + tax); std::cout << "Original price: $" << price << '\n' << "Tax: $" << tax << '\n' << "Final price: $" << final_price << '\n'; }
🌐
Wikipedia
en.wikipedia.org › wiki › Floor_and_ceiling_functions
Floor and ceiling functions - Wikipedia
February 5, 2026 - In mathematics, the floor function ... denoted ⌊x⌋ or floor(x). Similarly, the ceiling function maps x to the least integer greater than or equal to x, denoted ⌈x⌉ or ceil(x). For example, for floor: ⌊2.4⌋ = 2, ⌊−2.4⌋ ...
🌐
TechOnTheNet
techonthenet.com › c_language › standard_library_functions › math_h › ceil.php
C Language: ceil function (Ceiling)
October 3, 2025 - When compiled and run, this application will output: The ceil of 1.600000 is 2.000000 · Other C functions that are similar to the ceil function: floor function <math.h> Share on: SQL · Oracle / PLSQL · SQL Server · MySQL · MariaDB · PostgreSQL · SQLite · Excel · Access · Word · HTML · CSS · JavaScript · Color Picker · C Language · ASCII · Unicode · Linux · UNIX · Techie Humor · Introduction ·
🌐
W3Schools
w3schools.com › c › ref_math_floor.php
C Math floor() Function
C Examples C Real-Life Examples ... function is defined in the <math.h> header file. Tip: To round a number UP to the nearest integer, look at the ceil() function....
🌐
Post.Byes
post.bytes.com › home › forum › topic
Floor and ceil function - Post.Byes - Bytes
May 26, 2009 - Or if you hate macros as much as any CSc professor, you can do this: ... int CEIL(double var) { int integer = (int)var; if(var - integer == 0) return integer; else return integer + 1; } ... I have tried another way. I declared an array (arr[5]) and use ceil and floor function.
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 134000-problem-ceil-floor-functions.html
Problem With ceil() and floor() functions
January 22, 2011 - 0 0.000000 But according to the definition of floor and ceil function, it must have returned 2 3.000000 as result. Compiler: gcc 4.4.1 OS: Mandriva 2010 Thanks and Best Regards, Aakash Johari ... floor() returns a double, not an int; so use %f. Otherwise, to use %d, you'll have to cast the ...
🌐
Educative
educative.io › answers › what-are-the-floor-and-ceil-functions-in-cpp
What are the floor() and ceil() functions in C++?
The floor() method returns the largest possible integer less than or equal to the number passed as an argument. ... The ceil() function returns the smallest possible integer greater than or equal to the number passed as an argument.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-ceil-function
C ceil() Function - GeeksforGeeks
July 7, 2024 - It can be of type float, double, or long double. The ceil() function returns the smallest integer value greater than or equal to the input number as a double. Input: double number = 2.9; Output: The floor value of 2.9 is 3
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-runtime-library › reference › ceil-ceilf-ceill
ceil, ceilf, ceill | Microsoft Learn
July 9, 2025 - In a C program, unless you're using ... takes and returns a double. If you use the <tgmath.h> ceil() macro, the type of the argument determines which version of the function is selected. See Type-generic math for details. By default, this function's global state is scoped to the application. To change this state, see Global state in the CRT. For more compatibility information, see Compatibility. See the example for floor...
🌐
Reddit
reddit.com › r/cpp_questions › looking for a kind soul to assist with 'floor' and 'ceil' in c++
r/cpp_questions on Reddit: Looking for a kind soul to assist with 'floor' and 'ceil' in C++
December 8, 2022 -

Soooo, I am very green/new to any type of code and programming. I understand the base concept of the floor/ceil. Functions but unsure how to incorporate them to my current code. I can give brief details of deliverables. Prompt user to input 2 values to be converted from Celsius to Fahrenheit. Determine which of the 2 is the "start/stop" values. Once start and stop are determine, the program converts every value in the range input from user to Fahrenheit, in 1 degree increments.

I have all of the code complete.. my issue is floor and ceil functions just won't round up or down as expected. Not proficient enough to determine where my code needs to be tweaked. Please help. Thank you. The "start" value should round down and the stop value should round up. My code either rounds both up or down.

Willing to elaborate more if the above doesnt make sense.. with anyone willing to help.