# Rounding positive numbers?

Thomas Hayes
Posts:

**1,164**
Hi everyone

I just checked out the AMX tech note about using 'type_cast' for getting a + number rounded to the nearest whole number. Does anyone have a better example of how to do this? Where to put the code in the program, varibles etc. I want to round the run time from a projector to a whole number.

I just checked out the AMX tech note about using 'type_cast' for getting a + number rounded to the nearest whole number. Does anyone have a better example of how to do this? Where to put the code in the program, varibles etc. I want to round the run time from a projector to a whole number.

0

## Comments

861what happens when you typecast a float with value 2.2 to an integer is that the integer cant contain the decimal part, so its left off.

To make sure the values in between the x.0 and x.4 regions are being rounded down and the values in between the x.5 and x.9 regions are rounded up you just add 0.5

example:

you have your projector variable. I take from your earlier saying that your variable is a float? So let's say 19,2 hours.

FLOAT fProjectorHours = 19,2

INTEGER nProjectorHours = TYPE_CAST(fProjectorHours + 0.5)

now your integer nProjectorHours contains the value 19

i would reckon only using this 'conversion' for displaying the value, for example on a touchpanel, and keeping the 'original' float value intact...

hope this helps abit, im not really sure if i explained it in a nice way