Data Modeling

Fixed-point decimal precision and scale are capacity choices: precision controls total digits, scale controls fractional digits, and the difference between them controls how large the whole-number part can become. The common mistake is sizing only the stored column and forgetting that sums, products, averages, and ratios often need more room while they are being calculated.

What precision and scale mean in practice

A fixed-point decimal type is usually written as DECIMAL(p,s) or NUMERIC(p,s). The exact syntax and engine behavior vary by database, but the modeling idea is stable.

  • p is precision: the total number of digits.
  • s is scale: the number of digits to the right of the decimal point.
  • p - s is the number of digits available to the left of the decimal point.

For example, DECIMAL(9,2) has 9 total digits and 2 fractional digits. That leaves 7 digits for the whole-number part. It can represent values up to 9,999,999.99 in magnitude, before considering any database-specific constraints.

The sign is not usually counted as one of the precision digits. The decimal point is not counted either. This means precision is not a display width. It is numeric capacity.

Decimal type Total digits Fractional digits Whole-number digits Largest positive value pattern
DECIMAL(9,2) 9 2 7 9,999,999.99
DECIMAL(12,4) 12 4 8 99,999,999.9999
DECIMAL(18,6) 18 6 12 999,999,999,999.999999
DECIMAL(20,0) 20 0 20 99,999,999,999,999,999,999

Why intermediate calculations break before stored values do

A column can be correctly sized for each individual row and still be too small for the calculations built from those rows. This is where decimal modeling often fails in analytics systems.

Suppose an order line amount is stored as DECIMAL(12,2). That allows up to 10 digits to the left of the decimal point. A single value can be as large as 9,999,999,999.99. If a monthly dashboard sums up to one million such rows in a large group, the sum may need up to 16 whole-number digits, not 10.

The row-level column was not wrong. The aggregation capacity was wrong. A metric model, warehouse table, materialized table, or BI semantic layer that casts the result back into DECIMAL(12,2) can overflow, truncate, error, or force emergency widening later.

The durable rule is simple: size stored values and calculation results separately. A safe column for one row is not automatically a safe type for a sum, product, ratio, or average.

Operator rule

A decimal type that is safe for a row is not automatically safe for a metric. Size persisted inputs and calculated outputs as separate design decisions.

Rule 1: size the stored value from the largest legitimate value

Start with the value at the table grain. Ask: what is the largest legitimate value this row should store, in the chosen unit?

Then choose the number of whole-number digits and fractional digits independently.

  1. Choose the unit, such as dollars, kilograms, seconds, kilowatt-hours, or percentage points.
  2. Choose the table grain, such as one order line, one shipment event, one meter reading, or one invoice adjustment.
  3. Estimate the largest legitimate value at that grain, using business rules, contracts, product limits, or realistic operational constraints.
  4. Choose the fractional detail that must be retained for storage, not merely for display.
  5. Set precision as whole-number digits + scale.

If a row-level quantity needs up to 999,999 units and 3 fractional digits, it needs 6 whole-number digits and 3 fractional digits. A natural starting point is DECIMAL(9,3).

This is not accounting, tax, or policy advice. It is numeric representation. The business still has to define what values are valid and what fractional detail matters.

Rule 2: do not confuse storage scale with display rounding

Scale is not the same thing as how many decimals a dashboard shows. A value may need four or six fractional digits for accurate calculation but only two digits when presented to a human.

For example, a discount rate may be stored as DECIMAL(7,6) so that 0.125000 can be represented. A dashboard may display that same rate as 12.5%. Those are different decisions.

When teams use presentation rounding as the storage scale, later calculations become unnecessarily lossy. When teams use excessive scale everywhere without a reason, models become harder to reason about and may hit type limits sooner during multiplication.

A useful design question is: what is the smallest unit of meaning this value needs to preserve before any final presentation rounding?

Rule 3: budget extra whole-number digits for sums

Summing values increases the possible size of the whole-number part. The fractional scale usually stays the same, but the integer side needs more room.

A conservative rule for summing up to N non-null values of DECIMAL(p,s) is:

  • Input whole-number digits: i = p - s
  • Extra whole-number digits for count: ceil(log10(N))
  • Sum whole-number digits: i + ceil(log10(N))
  • Sum precision: sum whole-number digits + s

Hypothetical example: a table stores transaction amounts as DECIMAL(12,2). That gives 10 whole-number digits. If a reporting group can contain up to 500,000 rows, ceil(log10(500,000)) is 6. A conservative sum needs 16 whole-number digits plus 2 fractional digits, or DECIMAL(18,2).

This does not mean every sum in the warehouse must be sized against the entire table. Size against the largest legitimate group for that metric. A daily store total, a customer lifetime total, and a company-wide annual total may need different capacities.

Practical checkpoint

For sums, the scale often stays the same, but the whole-number side grows with the largest legitimate group size.

Rule 4: budget products and rates explicitly

Multiplication can increase both whole-number digits and fractional digits. If you multiply two declared decimal values without thinking about the result, the output may require far more capacity than either input.

A conservative modeling rule is:

  • Whole-number digits in product: add the whole-number digits of the inputs.
  • Fractional digits in product: add the scales of the inputs.
  • Then decide whether the result should be rounded or stored at that full intermediate scale.

Hypothetical counterexample: unit price is DECIMAL(8,2) and quantity is DECIMAL(9,0). The price has 6 whole-number digits and 2 fractional digits. The quantity has 9 whole-number digits. A worst-case product may need 15 whole-number digits and 2 fractional digits: DECIMAL(17,2). Storing the line amount as DECIMAL(10,2) would be much too small for the declared inputs.

Rates deserve special care. A rate column declared as DECIMAL(7,6) technically allows values up to 9.999999, even if the business expects rates between 0 and 1. If the business rule is actually 0 through 1, document and enforce that constraint instead of sizing every downstream calculation as if a 999.9999% rate were valid.

Rule 5: handle division and ratios deliberately

Division is different from addition and multiplication because many decimal divisions do not terminate. One divided by three cannot be represented exactly with a finite decimal scale.

That means ratios need an intentional output scale. Do not rely on whatever scale a database, transformation tool, or BI layer happens to infer.

For a ratio, decide:

  • What unit is the ratio expressed in: fraction, percent, basis points, units per hour, seconds per item, or another unit?
  • How many fractional digits are meaningful for analysis?
  • Where should rounding happen: in a modeled metric, a final presentation layer, or a persisted table?
  • What should happen when the denominator is zero or null?

For example, an on-time rate may be stored or modeled as a fraction with six fractional digits, such as DECIMAL(9,6), and then displayed as a percentage with one or two decimal places. The storage capacity and display format should be separate decisions.

Durations, measurements, and physical units need the same discipline

Fixed-point decimals are not only for currency-like amounts. They are also common for durations, distances, weights, energy usage, inventory quantities, and other measured facts.

The same capacity questions apply:

  • What is the unit of storage?
  • What is the largest legitimate value at the table grain?
  • How much fractional detail is meaningful from the source system or measurement process?
  • Will the value be summed, averaged, multiplied, or converted into another unit?

For durations, storing seconds as an integer may be better than storing hours as a high-scale decimal, depending on the use case. For sensor-like measures, scale should reflect meaningful measurement resolution rather than arbitrary decimal places.

Also remember that the word scale is overloaded. In decimal types, scale means digits after the decimal point. In statistics and measurement, scale may refer to spread, magnitude, or measurement level. Be explicit in documentation so readers know which meaning is intended.

Database behavior varies, so cast important results intentionally

Different SQL engines and data platforms have different rules for the result type of decimal arithmetic. Some widen sums. Some cap precision. Some round or error in ways that depend on settings, expressions, or function behavior.

The modeling principle is not vendor-specific: important numeric outputs should have an intentional type. If a modeled field is a contractual metric, dashboard metric, reconciliation measure, or downstream feature, do not leave its capacity to implicit inference.

In practice, this means checking the platform documentation and using explicit casts at stable boundaries, such as curated model columns, published metric tables, and exported datasets.

Use wider intermediate types where necessary, then cast once to the chosen output type after applying the intended rounding or validation rule.

Warning

Do not assume your SQL engine’s inferred decimal result type matches your metric definition. Cast important published outputs deliberately.

A practical sizing workflow for decimal columns

Use this workflow when adding a decimal column, rebuilding a metric, or reviewing a model that has overflow or reconciliation issues.

  1. Name the grain. Identify what one row represents.
  2. Name the unit. Decide whether the value is stored as dollars, cents, seconds, hours, percent, fraction, kilograms, or another unit.
  3. Choose storage scale. Use the smallest fractional detail that is meaningful and required before presentation.
  4. Choose row-level maximum. Define the largest legitimate value at the row grain.
  5. Compute row precision. Whole-number digits plus scale equals precision.
  6. List downstream operations. Include sums, averages, products, ratios, unit conversions, and joins to rates.
  7. Size each important result. Use wider capacity for aggregates and products.
  8. Decide final rounding points. Separate calculation precision from display formatting.
  9. Test boundary examples on paper. Use max values, max group sizes, zero denominators, negative values, and nulls.
  10. Document assumptions. Record the unit, scale, maximum, and reason for the chosen type.

This workflow is intentionally mechanical. Numeric correctness improves when capacity decisions are written down instead of inherited from whatever column type appeared first.

Operation What usually grows Sizing rule of thumb Example question
Store one row Depends on business maximum and unit Precision = whole-number digits + required scale What is the largest legitimate value for one row?
SUM Whole-number digits Add capacity for the largest group size How many rows can be summed into one metric value?
AVG Output scale may need more detail than input Choose a deliberate result scale How many decimals make the average meaningful?
Multiplication Whole-number digits and fractional digits Add input whole-number digits and input scales, then round intentionally if needed What is the largest valid combination of operands?
Division or ratio Fractional digits may not terminate Choose an output scale and denominator rule How should repeating decimals and zero denominators behave?
Unit conversion Scale and magnitude can both change Size the converted value, not just the source value Does converting seconds to hours or cents to dollars change required decimals?

Common failure modes when choosing precision and scale

Most decimal capacity problems come from a small set of modeling mistakes.

  • Copying source types without checking analytics use. A source column may fit one transaction but not a reporting aggregate.
  • Using display decimals as storage decimals. A dashboard showing two decimals does not prove the modeled value only needs two decimals.
  • Letting multiplication explode scale. Multiplying two high-scale values can create a result that is technically precise but impractical unless rounded intentionally.
  • Assuming rates are always less than one. If the type allows larger values but the business does not, enforce the business rule.
  • Ignoring group size. Sum capacity depends on how many rows can land in a group, not just on the source column.
  • Relying on implicit database inference. Result types for decimal arithmetic differ across systems and should be verified for important metrics.
  • Using one decimal type everywhere. A universal DECIMAL choice may be too small for some metrics and unnecessarily large or misleading for others.

Key takeaways

  • Precision is total digit capacity; scale is fractional digit capacity; whole-number capacity is precision minus scale.
  • Choose decimal types from the unit, grain, largest legitimate value, and required fractional detail.
  • Aggregates need their own capacity. A safe row-level decimal may be too small for a sum.
  • Multiplication can increase both whole-number digits and fractional digits, especially when quantities, prices, rates, or conversions are combined.
  • Ratios and divisions need intentional output scale because many decimal divisions do not terminate.
  • Database engines vary in decimal arithmetic behavior, so important published metrics should use explicit types and documented assumptions.

Next step

Pick one important decimal metric in your warehouse and write down its unit, grain, row-level maximum, storage scale, largest expected group size, downstream calculations, and final output type. If any step is unknown, that is the next modeling assumption to clarify.

Recommended next reads