Problem with floats (new to programming)

Hey first post. I have to write a program that takes a food bill and does 15% gratuity and rounds UP! I am using floating point numbers and cant figure out how to round up or, round at all >.>. I will post my code if that will help anybody help me :). Thanks in advance guys
In math.h are defined the functions floor() and ceil() that could help you

you can also see at:
http://www.cplusplus.com/forum/articles/3638/
Last edited on
You could do it without the math.h.

If you have your bill and you want to round it up, you can use the fact that if you cast the variable to an integer, the digits behind the point will simply be cut off. To round up, you simply have to add 1.

So, basically, it comes to that
1
2
3
4
5
int rounded_bill;
float bill;

bill = 15.32;
rounded_bil = bill+1;


int main
but won't this produce an error like this?

1
2
3
4
5
6
7
8
int rounded_bill;
float bill;

//...

//bill == 15.00
rounded_bill = bill + 1;
//rounded_bill == 16 
Last edited on
I was actually just looking to round the cents up.. for example

23.863 -> 23.87

I was thinking of doing +.01 to the number..

The only problem i think i would run into though is the fact that it auto rounds when its .005 and up.. so i would be adding an extra .o1

(it didnt post first time.. sorry if this is a repeat)
Hint: multiply by 100, do some calculations, then divide by 100.
Topic archived. No new replies allowed.