# PHP: Output Number with X Decimal Places

Question by Guest | 2015-04-23 at 16:53

I am calculating some percentages using PHP in order to display them under each other within a table.

Of course, the resulting values are differing in the amount of decimal places. However, I would like to show them all with the same fixed number of decimal places.

Is there any function in PHP for this? Finally, it is looking messy when there are the numbers 3.5, 1.23 and 2.74818 next to each other.

## Related Topics

### How many decimal places does Pi have?

Question | 1 Answer

### PHP: Rounding Numbers

Tutorial | 0 Comments

### Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places

Tutorial | 7 Comments

### PHP: Round number to two decimal places

Question | 2 Answers

### Delphi/Lazarus: Round Number to the next 10, 100 or 1000

Question | 1 Answer

### Delphi/Lazarus: Round Decimal Numbers up, down and normally

Tip | 0 Comments

### The first 100,000 Digits of Pi

Info | 0 Comments

## Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

## Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.

You can simply use the PHP function number_format for this.

Here is a small example:

As a first parameter, you can pass the number, as second parameter, the number of decimal places.

More information about it and how to adjust the decimal separator to your needs you can learn here.

2015-04-25 at 21:58