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

Drizzle ORM · Function

decimal

Drizzle's MySQL decimal() builder defines an exact fixed-point DECIMAL column. You can set precision, scale, and the value mode used by the schema.

How it works

Drizzle's MySQL decimal() column builder maps to the SQL DECIMAL type. Configure total precision and fractional scale, and optionally choose number or bigint mode for the application's value representation.

Syntax

decimal({ precision?: number, scale?: number, mode?: 'number' | 'bigint' })

Parameters

NameTypeDescription
precisionnumberOptional total number of digits; the documentation example uses precision: 30.
scalenumberOptional number of digits after the decimal point; the documentation example uses scale: 10.
mode'number' | 'bigint'Optional value mode shown as number or bigint in the documentation examples.

Returns

A Drizzle MySQL decimal column builder.

Key points

  • The MySQL decimal type is intended for exact fixed-point numeric values.
  • Precision counts all digits, whereas scale counts only digits to the right of the decimal point.
  • MySQL permits at most 65 digits of precision for this type.
  • Set number mode when the schema should expose decimal values through JavaScript number-oriented typing.
  • The builder also provides bigint mode for schemas that need bigint-oriented value handling.
  • Precision and scale can be supplied together to constrain the column's numeric shape.

Example: Define a MySQL decimal column

import { decimal, mysqlTable } from "drizzle-orm/mysql-core";

export const products = mysqlTable("products", {
  price: decimal({ precision: 10, scale: 2, mode: "number" }),
});

Defines a MySQL DECIMAL column with ten total digits, two fractional digits, and number-mode values.

When to use it

Store exact amounts

Financial or monetary columns where decimal precision must be preserved.

Constrain numeric shape

Schemas requiring bounded total and fractional digit counts.

Select value mode

Applications that need a chosen numeric representation in their typed schema.

Interview questions

QWhat does Drizzle's MySQL decimal() builder represent?

The MySQL decimal() builder represents an exact fixed-point number. Its precision is the total digit count, while scale is the number of digits after the decimal point.

Follow-up: Why use DECIMAL for prices? Because exact fixed-point representation avoids the rounding behavior associated with binary floating-point values.

QHow can the returned value mode be configured?

Use decimal({ precision: 30, mode: 'number' }) when the application should use JavaScript numbers, or mode: 'bigint' when bigint-mode values are appropriate. The page's examples show both modes.

Follow-up: What trade-off should be checked before choosing number mode? Verify that the required values remain safely representable by JavaScript numbers.

QHow do precision and scale affect the generated SQL type?

decimal({ precision: 30, scale: 10 }) produces a DECIMAL declaration with precision 30 and scale 10. Omitting these options leaves the corresponding SQL declaration unconstrained in the generated example.

Follow-up: What does scale control independently of precision? It determines how many digits are stored after the decimal point.

  • mysqlTable
  • customType
  • DECIMAL

Source: MySQL column types - Drizzle ORM. Checked 2026-10-16.