Round only at the display stage

Use the opposite Shift key for paired punctuation. · 174 words

Rounding belongs in presentation, not in calculation fields. The source is 3 packages, each weighing 2.345 kg. Ask for raw_weight_kg and display_weight. Tell the model to multiply 3 by 2.345, store 7.035 without rounding, and create the display string "7.04 kg" by rounding only that string to two decimals. Expected output: {"package_count":3,"weight_kg_each":2.345,"raw_weight_kg":7.035,"display_weight":"7.04 kg"}. Check raw_weight_kg against 3 * 2.345. Then round that value separately for display. This keeps a precise result for later work.

Test the rule with currency. The source price is 45.50 EUR at an exchange rate of 1.0843 USD per EUR. Ask for raw_usd, calculated from the full values, and display_usd, formatted to two decimals. The raw result is 49.33565, while display_usd should be "49.34 USD". Add: Never round raw_usd; use display fields only for rounded text. Verify by multiplying 45.50 by 1.0843 and comparing the result with raw_usd. Then round that raw result to two decimals and compare it with display_usd. If raw_usd is 49.34, the model rounded too early; if display_usd is 49.33, it used the wrong rounding rule.

Check your recall

For a raw result of 49.33565 USD, which value should remain exact and which value should be rounded?

Check your answer

Keep 49.33565 in the raw calculation field and put "49.34 USD" in the display field. Rounding the raw field would discard precision needed by later calculations.

Sources and credits

Original KeyTouch lesson. Background reading · JSON Schema · Understanding JSON Schema.