You are here: decimal formatting with sprintf? « PHP Programming Language « IT news, forums, messages
decimal formatting with sprintf?

Posted by lawpoop on 11/12/41 12:00

Hello all --

I'm trying to format decimal numbers for a report. I would have to
have the number with leading zeros to the tens' place, and trailing
zeros to the thousandths' place.

I'm using sprintf("%02.2f", $num) to get the following results:

0.5 : 0.50
0.55 : 0.55
5.5 : 5.50
55.5 : 55.50
55.55: 55.55
100 : 100.00

It does the trailing zeros correctly, but not the leading zeros. I
would like 5.5 to become 05.50 .

I don't really understand the syntax of the format specifier of
sprintf. Can someone help me out or point me to a good tutorial?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация