> I don't know how to write the code for round command?
For example if more than .5 then round up,if less than .5
round down such as 4.3 round to 4.0 and 5.5 round to 6.0
A simple trick is to add 0.5 to the value (if positive) or remove 0.5 (if
negative). By converting the value back into an integer it will
automatically round to the right value.
Ex:
4.0 + 0.5 = 4.5... truncated (cast) = 4.0
4.3 + 0.5 = 4.8... truncated (cast) = 4.0
4.5 + 0.5 = 5.0... truncated (cast) = 5.0
4.7 + 0.5 = 5.2... truncated (cast) = 5.0
Here's a macro that implements the "logic" :
#define ROUND_INT(x) ((int)((x)+(((x)>0)?0.5:-0.5)))
If you need it for a float/double, just cast back into one...
Alex.