Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounded division 1

Status
Not open for further replies.

scienzia

Programmer
Feb 21, 2002
160
IT
Is there an operator that gives as a result a rounded division.

I mean that 100 / 6 must give 17

(using floats is 16.66666.... , using int gives 16)

Thanks in advance




 
No a special operator.
It's so simple:
Code:
(int)((double)x/(double)y + 0.5)
 
Look at
Code:
floor()
ceil()
Both in math.h

--
 
floor() is round down, ceil() is round up. A common math (to a nearest int) rounding is as in the snippet above.
 
> A common math (to a nearest int) rounding is as in the snippet above.
Try it on something negative, say -2.7



--
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top