英文:
@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 用来处理像你目前使用的小数的方法。我不确定它是如何工作的,但我想 s
和 e
(符号和指数?)可能很重要,不应该被忽视。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论