What is the use of toFixed() method in JavaScript?

What is the use of toFixed() method in JavaScript?

JavaScript, JavaScript Method, Method, toFixed()

50 | 0 | 0

The toFixed() method returns a string, with the number written with a specified number of decimals.

let a = 5.456;

console.log(a.toFixed());       // 5

console.log(a.toFixed(0));      // 5

console.log(a.toFixed(2));      // 5.46

console.log(a.toFixed(4));      // 5.4560

console.log(a.toFixed(6));      // 5.456000

 

Comments (0)

🤔

No comments yet, be the first to help

Welcome to CodePits.

CodePits provide a collection of tutorials about many programming languages like PHP, Laravel Framework, Codeigniter Framework, Mysql Database, Bootstrap Front-end Framework, Jquery, Node JS, Ajax Example, APIs, CURL Example, Composer Packages Example, AngularJS, Ionic Framework, etc. 🙌

Other Posts

Categories

Tags

Comment