Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format a Decimal?

I need to format a decimal like this:

00.33
11.24
05.22

The problem is that when I retrieve 00.33 it outputs as 0.33.

I tried everything and can't get it to work correctly. I could do MySQL's Zerofill but I'm really trying to avoid that.

like image 262
Tom Avatar asked May 31 '09 00:05

Tom


1 Answers

sprintf("%05.2f", 0.33)
# or
"%05.2f" % 0.33
like image 157
Chuck Avatar answered Sep 19 '22 11:09

Chuck