Setting number of decimal places in Float (custom precision) #5121
|
When you have a float value in your schema, say: model Retailer {
createdAt DateTime @default(now())
discount Float @default(0.00)
slug String @id
title String
updatedAt DateTime @updatedAt
}The generated database doesn't have Is there any way to tell Prisma to use two decimal spaces, i.e., specify custom float precision? |
Replies: 3 comments 1 reply
|
Hey @AnandChowdhary 👋 Currently this would only be possible via Native types that will help you specify exactly the precision required in the form of custom types. Unfortunately this is only possible right now via introspection so you will need to create your table in the database first and then run The float type mappings which will be created are available here. Let me know if that works :) |
|
This is great, full support for native types has been added in prisma/prisma@v2.15.0! For example, setting generator client {
provider = "prisma-client-js"
previewFeatures = ["nativeTypes"]
}
model Product {
name String
price Decimal? @mysql.Decimal(10, 2)
}Note that this would now return a const product = prisma.product.findFirst();
const price = product.price; // This is a `Decimal`, so you should typecast it
const discountedPrice = product.price.toNumber() * 0.9; |
|
Hi there, To keep our discussions organized and focused on the most relevant topics, we’re reviewing and tidying up our backlog. As part of this process, we’re closing discussions that have already been marked as answered but remain open. If this discussion still requires further input or clarification, feel free to reopen it or start a new one with updated details. Your contributions are invaluable to the community, and we’re here to help! For more details about our priorities and vision for the future of Prisma ORM, check out our latest blog post: https://www.prisma.io/blog/prisma-orm-manifesto. Thank you for your understanding and ongoing support of the Prisma community! |
This is great, full support for native types has been added in prisma/prisma@v2.15.0!
For example, setting
pricewith two decimal places:Note that this would now return a
Decimal(not nativenumber):