If we chop a at nd digits, should we round up?
(a *decimal, nd int)
| 296 | |
| 297 | // If we chop a at nd digits, should we round up? |
| 298 | func shouldRoundUp(a *decimal, nd int) bool { |
| 299 | if nd < 0 || nd >= a.nd { |
| 300 | return false |
| 301 | } |
| 302 | if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even |
| 303 | // if we truncated, a little higher than what's recorded - always round up |
| 304 | if a.trunc { |
| 305 | return true |
| 306 | } |
| 307 | return nd > 0 && (a.d[nd-1]-'0')%2 != 0 |
| 308 | } |
| 309 | // not halfway - digit tells all |
| 310 | return a.d[nd] >= '5' |
| 311 | } |
| 312 | |
| 313 | // Round a to nd digits (or fewer). |
| 314 | // If nd is zero, it means we're rounding |
no outgoing calls
no test coverage detected
searching dependent graphs…