bhylu.com

Advertisements

JS Number Methods

Number methods format or inspect numeric values. ToFixed returns text, not another number.

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 price = 7.5;
const label = price.toFixed(2);
console.log(label, typeof label);

What happens

The output shows 7.50 and string.