Apr 19, 2005 #1 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
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
Apr 19, 2005 1 #2 ArkM IS-IT--Management Oct 21, 2002 1,819 RU No a special operator. It's so simple: Code: (int)((double)x/(double)y + 0.5) Upvote 0 Downvote
Apr 22, 2005 #4 Salem Programmer Apr 29, 2003 2,455 GB Look at Code: floor() ceil() Both in math.h -- Upvote 0 Downvote
Apr 24, 2005 #5 ArkM IS-IT--Management Oct 21, 2002 1,819 RU floor() is round down, ceil() is round up. A common math (to a nearest int) rounding is as in the snippet above. Upvote 0 Downvote
floor() is round down, ceil() is round up. A common math (to a nearest int) rounding is as in the snippet above.
Apr 29, 2005 #6 Salem Programmer Apr 29, 2003 2,455 GB > A common math (to a nearest int) rounding is as in the snippet above. Try it on something negative, say -2.7 -- Upvote 0 Downvote
> A common math (to a nearest int) rounding is as in the snippet above. Try it on something negative, say -2.7 --
Apr 29, 2005 #7 lionelhill Technical User Dec 14, 2002 1,520 GB I was wondering about that... shifts out by one. Upvote 0 Downvote