@@ -12,6 +12,7 @@ import (
1212const (
1313 AllowedCharacters = "0123456789.-eE"
1414 BigDecRegEx = "-?(?:[0|1-9]\\ d*)(?:\\ .\\ d+)?(?:[eE][+\\ -]?\\ d+)?"
15+ Precision = 128
1516)
1617
1718var (
@@ -28,24 +29,32 @@ type BigDecimal struct {
2829}
2930
3031func (bd * BigDecimal ) GetScaledValue () string {
31- unscaled , _ := new (big.Float ).SetString (bd .UnscaledValue )
32+ if bd .UnscaledValue == "" {
33+ return "0"
34+ }
3235
33- scalingFactor := new (big.Float ).SetFloat64 (1 )
36+ // Use SetPrec to maintain full precision
37+ unscaled := new (big.Float ).SetPrec (Precision ) // Use high precision to avoid scientific notation
38+ unscaled , _ = unscaled .SetString (bd .UnscaledValue )
39+
40+ scalingFactor := new (big.Float ).SetPrec (Precision ).SetFloat64 (1 )
3441 for i := 0 ; i < abs (bd .Scale ); i ++ {
3542 scalingFactor .Mul (scalingFactor , big .NewFloat (10 ))
3643 }
3744
3845 var scaledValue * big.Float
3946 if bd .Scale >= 0 {
40- scaledValue = new (big.Float ).Mul (unscaled , scalingFactor )
47+ scaledValue = new (big.Float ).SetPrec ( Precision ). Mul (unscaled , scalingFactor )
4148 } else {
42- scaledValue = new (big.Float ).Quo (unscaled , scalingFactor )
49+ scaledValue = new (big.Float ).SetPrec ( Precision ). Quo (unscaled , scalingFactor )
4350 }
4451
4552 if bd .Sign == 1 {
4653 scaledValue .Neg (scaledValue )
4754 }
48- return strings .TrimSuffix (strings .TrimRight (scaledValue .Text ('f' , bd .Scale ), "0" ), "." )
55+
56+ // Force format without scientific notation
57+ return strings .TrimSuffix (strings .TrimRight (scaledValue .Text ('f' , abs (bd .Scale )), "0" ), "." )
4958}
5059
5160func abs (x int ) int {
0 commit comments