FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplatesGuides
Release Notes
Source514
  1. MooseStack
  2. Data Types
  3. Decimal Types

On this page

Decimal(P, S)Common Precision PatternsType Mapping ReferenceSee Also

Decimal Types

Decimals provide fixed-point precision, ideal for financial calculations where floating-point errors are unacceptable.

Decimal(P, S)

A decimal number with P total digits (precision) and S digits after the decimal point (scale).

from moose_lib import clickhouse_decimal class FinancialData(BaseModel):    amount: clickhouse_decimal(10, 2)   # Decimal(10,2)    rate: clickhouse_decimal(5, 4)      # Decimal(5,4)    fee: clickhouse_decimal(8, 3)       # Decimal(8,3)

Common Precision Patterns

Use CasePrecisionScaleExample Type
Currency (cents)102Decimal<10, 2>
Currency (4 decimals)124Decimal<12, 4>
Interest rates54Decimal<5, 4>
Percentages52Decimal<5, 2>
Scientific189Decimal<18, 9>

Type Mapping Reference

ClickHouse TypeTypeScript HelperTypeScript VerbosePython
Decimal(P,S)Decimal<P, S>string & ClickHouseDecimal<P, S>clickhouse_decimal(P, S)
When to use Decimal

Use Decimal for monetary values, rates, and any calculation where exact decimal representation matters. Floating-point types (Float32/Float64) can introduce rounding errors in these scenarios.

Storage size

ClickHouse stores Decimals based on precision:

  • P ≤ 9: 4 bytes (Decimal32)
  • P ≤ 18: 8 bytes (Decimal64)
  • P ≤ 38: 16 bytes (Decimal128)
  • P ≤ 76: 32 bytes (Decimal256)

Choose the smallest precision that fits your needs.

See Also

  • Integers — When you need whole numbers
  • Floats — When approximate precision is acceptable
  • ClickHouse Decimal — ClickHouse official documentation
  • Overview
Build a New App
  • 5 Minute Quickstart
  • Browse Templates
  • Existing ClickHouse
Add to Existing App
  • Next.js
  • Fastify
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
Moose Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs & Web Apps
Deployment & Lifecycle
  • Moose Migrate
  • Moose Deploy
Reference
  • API Reference
  • Data Types
    • Strings
    • LowCardinality
    • Integers
    • Floats
    • Decimals
    • Booleans
    • Date & Time
    • Network
    • Arrays
    • Maps
    • Nested
    • Tuples
    • Enums
    • Geometry
    • JSON
    • Nullable
    • Aggregates
  • Table Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Release Notes
Contribution
  • Documentation
  • Framework