0

Wanted to as a simple question.

Code:

$myarray = array(5.0000); echo round($myarray[0],2); 

Ouput:

5 

Why is the output 5 and not 5.00 ?

Thanks

2 Answers 2

2

It doesn't show the 0's after the decimal point if there are only 0's.

5.050 would be shown as 5.05...

you can have a look at the number_format function if you want to show the 0's.

Sign up to request clarification or add additional context in comments.

Comments

2

It's because round actually rounds off the data you give to it, it doesn't change how that data is printed.

If you want to specify how the data is output, look into using printf, such as:

printf ("%.2f\n", $myarray[0]); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.