Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Class

Decimal

Prisma.Decimal is Prisma Client's Decimal-field value type, backed by Decimal.js. Construct it with a numeric value and use Decimal.js arithmetic methods before passing it to a query.

How it works

Prisma exposes Decimal fields through Prisma.Decimal, which is backed by Decimal.js. Construct a value with Prisma.Decimal and use Decimal.js methods such as plus before passing it to a Prisma Client query; MongoDB does not currently support Decimal fields.

Syntax

new Prisma.Decimal(value)

Key points

  • Prisma.Decimal values are backed by Decimal.js rather than JavaScript's ordinary number type.
  • Import Prisma alongside PrismaClient, then instantiate Decimal through the Prisma namespace.
  • Decimal.js arithmetic methods can be chained while preparing a value for a Prisma query.
  • The available operations and behavior follow the Decimal.js implementation.

Common mistakes

  • Decimal fields are not currently supported when the Prisma datasource uses MongoDB.

Example: Create a Decimal value

import { PrismaClient, Prisma } from "@prisma/client";

const prisma = new PrismaClient();

async function main() {
  const sample = await prisma.sample.create({
    data: { cost: new Prisma.Decimal(24.454545).plus(1) },
  });
  console.log(sample.cost.toString());
}

main().finally(() => prisma.$disconnect());

Creates a Decimal value, performs exact Decimal.js arithmetic, and stores it in a Prisma Decimal field.

When to use it

Writing precise decimal data

Persisting monetary or other fixed-precision values in a relational database.

Calculating query values

Applying arithmetic before insertion or update.

Interview questions

QWhat is Prisma.Decimal, and what library powers it?

Prisma.Decimal is the Prisma Client representation for schema fields of type Decimal. It is implemented with the Decimal.js library, so Decimal.js operations can be used on values before they are written.

Follow-up: How would you add one to a Decimal value? Construct it with Prisma.Decimal and call .plus(1) before supplying it to the query data.

QHow do you write a Decimal value with Prisma Client?

Create a value with new Prisma.Decimal(value) and assign it to the Decimal field in the query data. The documentation demonstrates this with a create operation.

Follow-up: Can arithmetic be performed during construction of query data? Yes; the documented pattern is new Prisma.Decimal(24.454545).plus(1).

QWhat database limitation applies to Decimal fields?

Decimal is not currently supported as a field when MongoDB is the datasource. Applications using MongoDB should choose a supported representation instead of declaring a Decimal field.

Follow-up: Where should connector-specific Decimal mappings be checked? Use the Prisma schema reference, which documents default mappings and native database types.

  • Decimal.js
  • PrismaClient
  • Decimal field
  • Prisma schema reference

Source: Fields & types (Prisma ORM v7). Checked 2026-10-16.