Rounding positive numbers?
Thomas Hayes
Junior Member
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.
Comments
-
i dont think the technote can be anymore clearer and says it all.
what 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
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums