-1

I have found plenty of ways to add a zero to one side of a string and also get rid of the zeroes, but the issue I am having is my numbers come back like this:

 10
 6.9

And I need to keep zeroes on either side of decimal place like this:

 10.00
 06.90

now excuse me if i am just not searching with the correct terminology but i cant find the answer here

i need to keep leading and trailing zeroes intact

Dynamite Media
  • 159
  • 2
  • 10

1 Answers1

1
$out=number_format($number,2,'.','0');

echo ($out<10)?"0".$out:$out;

By using the number_format function you can get the decimal values after dot and ternary operator for make the round with decimal values

lalithkumar
  • 3,480
  • 4
  • 24
  • 40
  • this could be the answer. – lalithkumar Mar 28 '17 at 08:51
  • could you edit that to be formatted? thanks – Dynamite Media Mar 28 '17 at 08:54
  • edited the answer – lalithkumar Mar 28 '17 at 09:08
  • Whilst this code snippet is welcome, and may provide some help, it would be [greatly improved if it included an explanation](//meta.stackexchange.com/q/114762) of *how* and *why* this solves the problem. Remember that you are answering the question for readers in the future, not just the person asking now! Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Mar 28 '17 at 09:44