Rounding
A Programming Pattern |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
number
denotes the valueplace
denotes the place of interest (e.g.,
10s, 100s, etc...)truncated
by place
)value - truncated
and half of
place
(number/place)*place
is
(526/10)*10
or 520
number % place
is 6
place / 2
is 5520 + 10
or 530
(number/place)*place
is
(2086/100)*100
or 2000
num % place
is 86
100 / 2
is 502000 + 100
or
2100