Module 1 · Mathematical Language and Quantitative Reasoning Lesson 10 of 120

Rounding, Precision, Tolerance, and Significant Digits

Rounding a half-cent without guessing binary behavior.

2:41 clip31:47–34:28 in the full courseWatch on YouTube

Transcript

23 sentences · select one to jump there

Check your understanding

Can this nonnegative half-up snippet be reused unchanged for negative amounts?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

010-rounding-precision-tolerance-and-significant-digits.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 010 of 120
 * Rounding, Precision, Tolerance, and Significant Digits
 * Module 01: Mathematical Language and Quantitative Reasoning
 *
 * Scenario: Rounding a half-cent without guessing binary behavior
 * Rule:     half-up(10.005) = 10.01 under a decimal policy
 *
 * Try it:   Can this nonnegative half-up snippet be reused unchanged for negative amounts?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/rounding-precision-tolerance-and-significant-digits/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson010() {
  const thousandths = 10005; // exact decimal input units
  if (!Number.isInteger(thousandths) || thousandths < 0)
    throw new Error("Nonnegative integer thousandths only");
  const cents = Math.floor((thousandths + 5) / 10); // half-up
  const result = cents / 100; // 10.01
  return result;
}

export const checkedResult = 10.01;

// Run this file directly: npx tsx lessons/01-mathematical-language-and-quantitative-reasoning/010-rounding-precision-tolerance-and-significant-digits.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson010(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

10.01

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

half-up(10.005) = 10.01 under a decimal policy