M Logo
๐Ÿ“ TypeScript from Zero ยท Part 3 of 50

TypeScript from Zero: Numbers and Math

November 6, 2026

Episode 3 of TypeScript from Zero: numbers and math. TypeScript has one type for numbers, called number; whole numbers and decimals are both numbers. We use the operators and the Math helpers, meet the famous 0.1 + 0.2 surprise and NaN, and fix a typo with tsc. All code below is the final code from the video.

bash
cd hello-ts
touch numbers.ts
code .

1. Plus and minus

ts
const apples = 7;
const people = 3;
console.log(apples + people);
console.log(apples - people);
text
10
4

2. Times and divide

* multiplies and / divides. Division always gives the exact answer, not a rounded one:

ts
console.log(apples * people);
console.log(apples / people);
text
21
2.3333333333333335

3. Remainder and power

% gives the remainder (handy to check if a number is even). ** is "to the power of":

ts
console.log(apples % people);
console.log(2 ** 10);
text
1
1024

4. The Math helpers

ts
console.log(Math.round(apples / people));
console.log(Math.max(4, 9, 2));
text
2
9

5. 0.1 + 0.2

ts
console.log(0.1 + 0.2);
text
0.30000000000000004

Computers store decimals in binary, and some decimals do not fit exactly. This is true in every language. For money, count cents as whole numbers.

6. NaN

Number() turns text into a number. For text that is not a number it gives NaN, "Not a Number", which is still of type number:

ts
console.log(Number("abc"));
text
NaN

Always check results that come from text.

7. A typo in a Math helper

ts
console.log(Math.rond(2.6));

Node prints all the lines before and then crashes:

text
TypeError: Math.rond is not a function

tsc finds it first and suggests the fix:

bash
npx tsc --noEmit numbers.ts
text
numbers.ts:13:18 - error TS2551: Property 'rond' does not exist on type 'Math'. Did you mean 'round'?

Correct the name to Math.round(2.6): tsc prints nothing, and the program runs to the end (the last line prints 3).

Final code

ts
const apples = 7;
const people = 3;
console.log(apples + people);
console.log(apples - people);
console.log(apples * people);
console.log(apples / people);
console.log(apples % people);
console.log(2 ** 10);
console.log(Math.round(apples / people));
console.log(Math.max(4, 9, 2));
console.log(0.1 + 0.2);
console.log(Number("abc"));
console.log(Math.round(2.6));
text
10
4
21
2.3333333333333335
1
1024
2
9
0.30000000000000004
NaN
3

Recap

  • One type, number; operators + - * / % **.
  • Math.round, Math.max and friends; the decimal surprise; NaN.

Next episode: Strings.

ยฉ 2026 All Rights Reserved By Mahmudul Alam