IsInteger returns true when decimal can be represented as an integer value, otherwise, it returns false.
()
| 1267 | |
| 1268 | // IsInteger returns true when decimal can be represented as an integer value, otherwise, it returns false. |
| 1269 | func (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. |
| 1288 | func abs(n int32) int32 { |