Kumar Ishan

Kumar Ishan

2 Articles Published

Articles by Kumar Ishan

2 articles

How to format a float in JavaScript?

Kumar Ishan
Kumar Ishan
Updated on 15-Mar-2026 6K+ Views

In JavaScript, formatting floating point numbers means controlling how many decimal places are displayed or how the number is rounded. There are several built-in methods to format floats, each with different behaviors for rounding and precision control. Math.round() Method Math.floor() Method Math.ceil() Method toFixed() Method toPrecision() Method Math.round() Method The Math.round() method rounds a number to the nearest integer. For decimal precision, multiply by 10^n, round, then divide by 10^n. Syntax Math.round(num) ...

Read More

How to format a number with two decimals in JavaScript?

Kumar Ishan
Kumar Ishan
Updated on 15-Mar-2026 102K+ Views

This tutorial will teach us how to format a number with two decimals using JavaScript. Formatting a number means rounding the number up to a specified decimal place. In JavaScript, we can apply many methods to perform the formatting. Some of them are listed as follows − The toFixed() Method Math.round() Method Math.floor() Method Math.ceil() Method Using toFixed() Method (Recommended) The toFixed() method formats a number with a specific number of digits to the right of the decimal. It returns a string representation ...

Read More
Showing 1–2 of 2 articles
« Prev 1 Next »
Advertisements