MCPcopy
hub / github.com/pquerna/ffjson / shouldRoundUp

Function shouldRoundUp

fflib/v1/decimal.go:298–311  ·  view source on GitHub ↗

If we chop a at nd digits, should we round up?

(a *decimal, nd int)

Source from the content-addressed store, hash-verified

296
297// If we chop a at nd digits, should we round up?
298func 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

Callers 2

RoundMethod · 0.70
RoundedIntegerMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…