@db.Decimal 在 Prisma 中表示 “s”, “e”, 和 “d”。

huangapple go评论94阅读模式
英文:

@db.Decimal in Prisma ("s", "e", "d")

问题

当我在 schema.prisma 中写入以下代码时:

value            Decimal?             @db.Decimal(7, 4)

当我从数据库中获取值时,我总是得到以下结果:

"value": {
      "s": 1,
      "e": 0,
      "d": [
        1
      ]
}

其中 "d" 是我的真实值。

我不想要 "s" 和 "e",我只想要 "value": 1。

英文:

Why when i write in schema.prisma:

value            Decimal?             @db.Decimal(7, 4)

When i take value from db I always have:

"value": {
      "s": 1,
      "e": 0,
      "d": [
        1
      ]

where "d" is my real value.

I don't want to have "s" and "e". I just want to have "value": 1

答案1

得分: 0

你可以只使用 Float 替代(在大多数提供者中实际上使用双精度)。如果需要更高精度,你应该学习如何使用 Decimal.js,这是 Prisma 用来处理像你目前使用的小数的方法。我不确定它是如何工作的,但我想 se(符号和指数?)可能很重要,不应该被忽视。

英文:

You could just use Float instead (which actually uses double precision in most providers). If you need more precision you should learn how to use Decimal.js which is what Prisma uses to process decimals like you are currently using. I'm not sure how it works, but I'd imagine that s and e (sign and exponent?) are important and should not be ignored.

huangapple
  • 本文由 发表于 2023年8月5日 03:43:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定