Last change
on this file since 1122 was 1046, checked in by alloc, 8 years ago |
Daodan: Added Windows MinGW and build batch file
|
File size:
661 bytes
|
Rev | Line | |
---|
[1046] | 1 | # round.awk --- do normal rounding
|
---|
| 2 | #
|
---|
| 3 | # Arnold Robbins, arnold@skeeve.com, Public Domain
|
---|
| 4 | # August, 1996
|
---|
| 5 |
|
---|
| 6 | function round(x, ival, aval, fraction)
|
---|
| 7 | {
|
---|
| 8 | ival = int(x) # integer part, int() truncates
|
---|
| 9 |
|
---|
| 10 | # see if fractional part
|
---|
| 11 | if (ival == x) # no fraction
|
---|
| 12 | return ival # ensure no decimals
|
---|
| 13 |
|
---|
| 14 | if (x < 0) {
|
---|
| 15 | aval = -x # absolute value
|
---|
| 16 | ival = int(aval)
|
---|
| 17 | fraction = aval - ival
|
---|
| 18 | if (fraction >= .5)
|
---|
| 19 | return int(x) - 1 # -2.5 --> -3
|
---|
| 20 | else
|
---|
| 21 | return int(x) # -2.3 --> -2
|
---|
| 22 | } else {
|
---|
| 23 | fraction = x - ival
|
---|
| 24 | if (fraction >= .5)
|
---|
| 25 | return ival + 1
|
---|
| 26 | else
|
---|
| 27 | return ival
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.