将小数存储到 pgtype numeric 中

发布于 2025-01-20 00:05:45 字数 630 浏览 3 评论 0原文

我正在使用 pgtype.NumRange 。下限和上限的类型为 pgtype.Numeric。 pgtype.Numeric 有以下字段

type Numeric struct {
    Int              *big.Int
    Exp              int32
    Status           Status
    NaN              bool
    InfinityModifier InfinityModifier
}

我想我应该能够使用 IntExp 字段的组合来表示任何数字,但我不知道如何到,因为 big.Int 和 `int32' 是整数类型。

Postgres 文档 中,我可以看到 numrange 可以采用任何下限和上限中的十进制值,并且数据类型 numeric 是十进制类型的超集。所以我知道我应该能够使用小数,但是 我该怎么办?

I was working with pgtype.NumRange. The lower and upper bounds are typed pgtype.Numeric. pgtype.Numeric has the following fields

type Numeric struct {
    Int              *big.Int
    Exp              int32
    Status           Status
    NaN              bool
    InfinityModifier InfinityModifier
}

I guess I'm suppose to able to represent any number using the duo of the Int and Exp fields, but I don't know how to, as big.Int and `int32' are integer types.

From Postgres docs, I can see that numrange can take decimal values in any of lower and upper bounds and data type numeric is a superset of decimal type. So I know I should be able to use decimals, but
how can I go about this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文