18800 / 100.0f
gives 18.
how can I make it round, and return 19 ?
simplicity and speed counts
18800 / 100.0f
gives 18.
how can I make it round, and return 19 ?
simplicity and speed counts
18800 is an integer, it must be casted to float and rounded like this: round((float)18800 / 100.0f)
Are you sure? 18800 / 100.0f should equal 188.
Anyhow, the basic rule for rounding integers that truncate is to add half the divisor before dividing. In your case, if you meant 18800 / 1000 = 18, you add half the divisor (1000) or 500 to 18800 which gives you 19300 then divide by 1000 for 19.
If speed and simplicity counts, why use floating-point?
thank you all, half divisor is a great solution, the bad math and float was just my mess while "inventing" a way to ask this question, simplifying code from memory