bhylu.com

Advertisements

JS Numbers

JavaScript Number values include integers and fractions. Many decimal fractions cannot be represented exactly.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const total = 0.1 + 0.2;
console.log(total);
console.log(total.toFixed(2));

What happens

The raw value shows floating-point rounding; formatting gives 0.30.