fix: #400 for int64 formating when exp <= 0

This commit is contained in:
zenix 2022-02-15 18:24:21 +09:00
parent 1af4912566
commit 7455279517

View File

@ -793,6 +793,9 @@ func (dn Value) Int64() int64 {
if 0 < dn.exp && dn.exp < digitsMax && if 0 < dn.exp && dn.exp < digitsMax &&
(dn.coef%pow10[digitsMax-dn.exp]) == 0 { // usual case (dn.coef%pow10[digitsMax-dn.exp]) == 0 { // usual case
return int64(dn.sign) * int64(dn.coef/pow10[digitsMax-dn.exp]) return int64(dn.sign) * int64(dn.coef/pow10[digitsMax-dn.exp])
} else if dn.exp <= 0 && dn.coef != 0 {
result := math.Log10(float64(dn.coef)) - float64(digitsMax) + float64(dn.exp)
return int64(dn.sign) * int64(math.Pow(10, result))
} }
if dn.exp == digitsMax { if dn.exp == digitsMax {
return int64(dn.sign) * int64(dn.coef) return int64(dn.sign) * int64(dn.coef)