Setting number of decimal places in Float (custom precision) #5121
-
Beta Was this translation helpful? Give feedback.
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 :) |
Beta Was this translation helpful? Give feedback.
-
|
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; |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.

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):