MCPcopy
hub / github.com/shopspring/decimal / IsInteger

Method IsInteger

decimal.go:1269–1285  ·  view source on GitHub ↗

IsInteger returns true when decimal can be represented as an integer value, otherwise, it returns false.

()

Source from the content-addressed store, hash-verified

1267
1268// IsInteger returns true when decimal can be represented as an integer value, otherwise, it returns false.
1269func (d Decimal) IsInteger() bool {
1270 // The most typical case, all decimal with exponent higher or equal 0 can be represented as integer
1271 if d.exp >= 0 {
1272 return true
1273 }
1274 // When the exponent is negative we have to check every number after the decimal place
1275 // If all of them are zeroes, we are sure that given decimal can be represented as an integer
1276 var r big.Int
1277 q := new(big.Int).Set(d.value)
1278 for z := abs(d.exp); z > 0; z-- {
1279 q.QuoRem(q, tenInt, &r)
1280 if r.Cmp(zeroInt) != 0 {
1281 return false
1282 }
1283 }
1284 return true
1285}
1286
1287// Abs calculates absolute value of any int32. Used for calculating absolute value of decimal's exponent.
1288func abs(n int32) int32 {

Callers 2

TestDecimal_IsIntegerFunction · 0.80

Calls 3

absFunction · 0.85
QuoRemMethod · 0.80
CmpMethod · 0.80

Tested by 2

TestDecimal_IsIntegerFunction · 0.64