Store exact amounts
Financial or monetary columns where decimal precision must be preserved.
Drizzle ORM · Function
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.
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.
decimal({ precision?: number, scale?: number, mode?: 'number' | 'bigint' })| Name | Type | Description |
|---|---|---|
precision | number | Optional total number of digits; the documentation example uses precision: 30. |
scale | number | Optional 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. |
A Drizzle MySQL decimal column builder.
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.
Financial or monetary columns where decimal precision must be preserved.
Schemas requiring bounded total and fractional digit counts.
Applications that need a chosen numeric representation in their typed schema.
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.
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.
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.
mysqlTablecustomTypeDECIMAL