0 votes
asked in C++ by

1 Answer

0 votes
answered by (8.2k points)


  Many people find the problem of their float points to integers, it always rounds down. A good way to use the round down, against itself, you can create code that causes it to go up, then round down, creating a rounding up OR down effect. 

The code I've always seen and used is: 

Integer = Float + .5 
Note: This works for almost all programming languages 

This will add .5 to the float number, and it will round down to be either the number above the original Float, or the number below. 
In --> Out 
1.1 --> 1 
1.5 --> 2 
1.7 --> 2 
1 --> 1