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).

import { Decimal } from "@514labs/moose-lib"; interface FinancialData {  amount: Decimal<10, 2>;     // Decimal(10,2) — up to 99999999.99  rate: Decimal<5, 4>;        // Decimal(5,4) — up to 9.9999  fee: Decimal<8, 3>;         // Decimal(8,3) — up to 99999.999}

You can also use the verbose syntax:

import { ClickHouseDecimal } from "@514labs/moose-lib"; interface FinancialDataVerbose {  amount: string & ClickHouseDecimal<10, 2>;  rate: string & ClickHouseDecimal<5, 4>;}

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
FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplates
Changelog
Source506
  • Overview
  • Quick Start
  • Templates / Examples
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
MooseStack in your App
  • App / API frameworks
Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs
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
  • Changelog
Contribution
  • Documentation
  • Framework