-
Notifications
You must be signed in to change notification settings - Fork 32
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
[typing] Clean up NewDecimalWithPrecision
#778
Conversation
@@ -4,6 +4,13 @@ import ( | |||
"fmt" | |||
) | |||
|
|||
const ( | |||
DefaultScale int32 = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved these constants too since they are only used for decimal details.
|
||
// This is typically not possible, but Postgres has a design flaw that allows you to do things like: NUMERIC(5, 6) which actually equates to NUMERIC(7, 6) | ||
// We are setting precision to be scale + 1 to account for the leading zero for decimal numbers. | ||
precision = scale + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we don't need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we have this exact logic in NewDetails()
and we don't read from Decimal.Precision()
except for tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. We should refactor the precision function then
func (d *Decimal) Precision() int32 {
return NewDetails(d.precision, d.Scale()).Precision()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just as soon as kill Precision
, we don't need it.
We don't need to duplicate the logic for handling invalid decimal precisions since we never read from
Decimal.Precision()
.