Currency values and decimal precision
Use this page when you design financial reporting, cost allocation, or billing. It shows how to keep amounts exact from the source to the report, how to keep each amount with its currency, and where to round.
Precision and scale
In DECIMAL(p,s), the precision p is the total number of digits and the scale s is the number of digits after the decimal point. The maximum p is 38. DECIMAL(38,12) leaves 26 digits before the decimal point, and DECIMAL(38,18) leaves 20. Declare both values explicitly, with enough room for small rates and for large totals.
A larger type does not make a source more accurate. Padding 1.23 to 1.230000000000 does not bring back digits that were lost earlier. The number of decimals that a report shows is presentation only. It does not change the stored amount.
Choose types at each step
| Step | Rule |
|---|---|
| Extract and Load | Declare exact integer or decimal types, up to 38 digits. |
| Transform | Columns that do not depend on each other can keep different scales. |
| Charge input | Exact integers, or decimals of type DECIMAL(38,12) |
| Charge result | DECIMAL(38,12) |
| Cube and report | A monetary measure keeps its currency. A report can show fewer decimals. |
| Export | Raw values and currency codes stay in separate fields. |
- For a decimal column in JSON or NDJSON, send a decimal string such as
"12.340000000000". The Load job rejects a JSON number with a fraction. See Loaders. - A Parquet
FLOATorDOUBLEvalue does not become exact when you cast it. - If a source has digits beyond scale 12, keep the original value in the Transform job and record how you convert it for the Charge job.
Join amounts without changing their precision
A join connects rows. It does not force two amount columns to the same decimal type. If you join a daily_cost of type DECIMAL(38,18) to a published_cost of type DECIMAL(38,12) and select both, each column keeps its own type and value.
Precision does not make a join correct. If one customer matches three lookup rows, the join repeats the same cost three times. Assert that the key is unique, and reconcile row counts and totals before you aggregate.
When values share one column
Values need one common type when they enter the same output column: when one reader combines several Parquet objects, and in UNION, INTERSECT, and EXCEPT.
Hypermeter allows compatible decimal types. It refuses, with a message, a combination that would make the scale smaller or turn a decimal into another type. At the maximum precision, a common type can still lose fraction digits.
When you combine different scales on purpose, choose the common type and the rounding rule yourself. These checks do not cover arithmetic, comparisons, CASE, COALESCE, or explicit casts.
Calculate with exact operands
Use a Charge Product measure for quantity times rate and a Charge Ratio measure for division.
Decimal division in SQL gives an approximate floating-point result. A cast, an alias, or a currency label does not make it exact again. A Charge job rejects approximate operands for exact calculations. Keep approximate ratios for analysis apart from the amounts that you bill.
See Preserve exact money provenance and the Charge template reference.
Charge rounding
A Charge job rounds every exact result to 12 decimal places. A value exactly halfway rounds to the even digit. You do not choose a scale or a rounding mode. See Chargers.
A Currency unit labels a value with its currency. It does not change the arithmetic and it does not round. A per-token price of 0.000000638878 stays 0.000000638878, and times 34775911 tokens it gives 22.217564467858.
With pricing rules and allocation, the allocated rows add up to the rounded total of the group. Do not round allocated rows again if they must keep adding up. See Charging rules.
Choose where to round
Suppose one million events each cost 0.0000004 in the same currency, and the invoice is in whole cents.
| Policy | Result |
|---|---|
| Round every event to cents, then sum | 0.00 |
| Sum the exact amounts, then round to cents | 0.40 |
The boundary decides the bill: event, line item, customer period, or pricing group. A Charge job keeps 12 decimal places, so both policies stay possible. Round explicitly at the boundary that you agree on, for example in the Transform job that converts amounts to cents.
Fixed and dimension-bound currency
A monetary measure is bound to its currency in one of two ways:
- Fixed currency: every value has one declared code, such as EUR.
- Dimension-bound currency: each row takes its code from a currency dimension, such as Source currency.
A cube can hold several pairs of amount and currency:
source_amount + source_currency
billing_amount + billing_currency
reporting_amount + reporting_currency
Each measure keeps its own binding. There is no currency setting for a whole cube, space, or view. You set the binding in the Charge job. See Chargers. Fields in a space or a view take their meaning from their inputs. They cannot relabel a value into another currency.
Currency minor units
ISO 4217 defines currency codes and minor units: EUR and USD have two decimal places, JPY has none, and KWD has three.
Minor units do not set the precision of rates, and a currency code does not choose a rounding policy for invoices, tax, or payments. Agree on these with the business owner and the receiving system. Two decimals in a report are not a two-decimal accounting entry.
Safe aggregation
You can sum a fixed-currency measure. You can aggregate a dimension-bound measure only when every result cell has one currency:
- Group by its currency dimension, for example Source cost by Source currency.
- Or apply a filter that leaves exactly one currency code, such as
Source currency = EUR.
Hypermeter refuses a query when the filters of the report and the space together do not prove one currency. Filters with or, ranges, exclusions, or several codes do not count.
Tables and pivots can keep currencies apart as rows or columns. A chart must not put different currencies on one axis or in one stack.
Apply the same care in Transform SQL. Reporting checks cannot repair a mixed-currency total that you calculated upstream.
For a blended unit rate, divide total cost by total quantity within one currency. An average of row rates can give another answer.
Convert currency through Transform and Charge
Hypermeter has no built-in exchange rates and does not convert at query time. You build conversion into the workflow: a Transform job selects the rate, and a Charge job calculates the converted amount. Publish the source amount and the converted amount as separate monetary measures.
Keep these fields with the calculation:
source_amount
source_currency
normalized_amount
reporting_currency
exchange_rate
exchange_rate_date_or_period
exchange_rate_source
exchange_rate_policy_or_version
- State the direction of the rate. At
1.08 USD per EUR,100 EURtimes the rate is108 USD. An inverse rate needs a division: use a ChargeRatiomeasure. - Join the rate by source currency, target currency, date or period, and policy. Assert exactly one rate per input row.
- For a missing, stale, or overlapping rate, let the run fail or apply a fallback that the business approved. Do not use zero or the latest rate silently.
- Bind Source amount to Source currency and Normalized amount to Reporting currency. Use a fixed reporting currency only when every row has that code.
- If rows have different rates, convert before you aggregate. A total converted with one rate can differ.
Spaces, views, and presentation
If a space hides a currency dimension, it also hides the monetary measures and calculations that depend on it.
A view can change only the minimum and maximum fraction digits and the negative style, standard or accounting. It cannot change the currency code.
- Exact decimals keep the scale of the source unless you set a maximum number of fraction digits. The maximum rounds the displayed text, not the stored amount.
- Compact notation is not available for exact decimals.
- The locale of the viewer changes separators and the place of the symbol.
€1,234.50and1.234,50 €are the same amount. - A displayed total can differ from the sum of the rounded values on screen. Reconcile raw values.
Exports
JSON and CSV exports put each raw monetary value next to a currency-code field. An export fails when a required code is missing, not valid, or ambiguous.
Parse exported amounts as decimals, not as floating-point numbers. Test the import settings of a spreadsheet with known high-precision values before you reconcile with it.
Validate the implementation
Preview with representative data, then add assertions that run on the full output. Test these cases:
- Very small rates and large totals fit the declared scale and range.
- Positive and negative halfway values follow the agreed rounding rule and boundary.
- An assertion catches duplicate customer or exchange-rate keys before aggregation.
- Missing amounts, missing rates, and zero denominators fail or get the declared default. Nothing becomes zero silently.
- Grouped and single-currency results succeed. Ambiguous totals fail.
- Allocated rows add up to the rounded group amount.
- A rerun reproduces the expected result from the kept source and rate data.
- Exported raw values and codes match the result.
When a precision check fails, correct the source types or the calculation. Do not silence the check by converting amounts to DOUBLE.