Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- sprintf and negative number sign?
March 26, 2008, 7:53 pm
rate this thread
I have sprintf formatting a number that goes on a report. I'm using
%05.2f to change 5.5 to 05.50, for example. However, I'm having a
problem with negative values -- I get -3.43, for example, because with
the sign, the whole length of the string is 5 characters.
I want a number that always has the tens place and the hundredths
decimal place, and the sign only when the number is negative. For
How do I get what I want? Obviously, I don't really understand the
syntax of sprintf. Thanks!
Re: sprintf and negative number sign?
You can't achieve that with a single sprintf call, at least I don't
think it's possible.
Perhaps add a "+" to force the sign at the beginning and then delete it.
str_replace("+", "", sprintf("%+06.2f", 3.45));
CKFinder :: ajax web file browser