Setting number of decimal places in Float (custom precision) · prisma/prisma · Discussion #5121 · GitHub
Skip to content
Discussion options

You must be logged in to vote

This is great, full support for native types has been added in prisma/prisma@v2.15.0!

For example, setting price with two decimal places:

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 Decimal (not native number):

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;

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@nestcub
Comment options

Answer selected by AnandChowdhary
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants