-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MaxScale not working #149
Comments
@ericlagergren please any help on that is appreciated. I need to have only two digits after decimal point like 5.00. |
Could you provide an example of what you're trying right now? |
Here is the code
When I perform multiplication I see more than two digits after decimal point. |
It is a little bit unclear how package main
import (
"fmt"
"github.com/ericlagergren/decimal"
)
func main() {
ctx := decimal.Context{
MaxScale: 2,
RoundingMode: decimal.ToNearestAway,
}
x := decimal.WithContext(ctx).SetUint64(1).SetScale(999)
fmt.Printf("x=%v\n", x) // prints 1E-999
fmt.Printf("scale=%d\n", x.Scale()) // prints 999
fmt.Printf("maxscale=%d\n", x.Context.MaxScale) // prints 2
// How can x's scale be 999, if x's max scale is 2?
} (Should I'm not sure if this is by design or a bug, but it seems |
Similar code: https://play.golang.org/p/V4jIH6WX4W4 package main
import (
"fmt"
"github.com/ericlagergren/decimal"
)
func main() {
var decimalContext = decimal.Context{
MaxScale: 4,
Precision: 10,
}
a, _ := decimal.WithContext(decimalContext).SetString("100000")
b, _ := decimal.WithContext(decimalContext).SetString("0.123456789")
c := decimal.WithContext(decimalContext).Add(a, b)
fmt.Println("MaxScale: 4, Precision: 10")
fmt.Printf("a = %v\n", a)
fmt.Printf("b = %v\n", b)
fmt.Printf("c = %v\n", c)
decimalContext = decimal.Context{
MaxScale: 5,
Precision: 10,
}
a, _ = decimal.WithContext(decimalContext).SetString("100000")
b, _ = decimal.WithContext(decimalContext).SetString("0.123456789")
c = decimal.WithContext(decimalContext).Add(a, b)
fmt.Println("MaxScale: 5, Precision: 10")
fmt.Printf("a = %v\n", a)
fmt.Printf("b = %v\n", b)
fmt.Printf("c = %v\n", c)
decimalContext = decimal.Context{
MaxScale: 4,
Precision: 20,
}
a, _ = decimal.WithContext(decimalContext).SetString("100000")
b, _ = decimal.WithContext(decimalContext).SetString("0.123456789")
c = decimal.WithContext(decimalContext).Add(a, b)
fmt.Println("MaxScale: 4, Precision: 20")
fmt.Printf("a = %v\n", a)
fmt.Printf("b = %v\n", b)
fmt.Printf("c = %v\n", c)
}
|
I am trying to have fixed scale after multiply operations
I trient to set MaxScale before mult but the scale becomes twice.
What is the correct way to handle this?
The text was updated successfully, but these errors were encountered: