- Part of the
`Number` object, JavaScript's toFixed() method returns string-formatted integers and floating points. **Without argument**, you get a number **rounded to the nearest whole number**: `var ``num` = 5.3;

// Without arguments, will round to whole numbers:

alert( `num`.**toFixed**() ); // Rounded down

num = 7.5;

alert( `num`.**toFixed**() ); // Rounded up

- But it is most useful to display a certain precision for numbers after the period: the integer you pass as argument determines
**how many digits will be displayed after the decimal point**. Use "`2`" to show prices in dollars and cents (and other currencies), including unnecessary zeros: `var ``num` = 5.785;

alert( `num`.**toFixed**(*2*) ); // 5.79

num = 3.4;

alert( `num`.**toFixed**(*2*) ); // 3.40 - show an extra zero at the end!

**Caveat:** remember that **what you get back is a string**. If you re-use variables, make sure to explicitly convert back to integer or float by using `parseInt()` or `parseFloat()` methods.

- JavaScript will accept an argument between
`zero` (**same as passing no argument**) and `20`. Just remember that this argument is the same as the number of digits *shown* after the period. **Tip:** since `toFixed()` only affects the "mantissa" (digits on the right of the decimal point), you'll need to write a custom function to pad extra zeros in front of the integer part of numbers.

- The
**PHP equivalent** to JavaScript's toFixed() method is the **number_format() function**: `$num` = 5.1;

echo **number_format**( `$num`, 2 ) . '<br>'; // 5.10

echo **number_format**( 3, 2 ) . '<br>'; // 3.00

// European notation, with comma for decimal and space to separate thousands:

echo **number_format**( 12345, 2, ',', ' ' ); // 12 345,00