Re: Money formatting (Less Verbose)

From: Date: Tue, 06 Aug 2002 17:19:32 +0000
Subject: Re: Money formatting (Less Verbose)
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-111409@lists.php.net to get a copy of this message
"Kondwani Spike Mkandawire" <kondwani@cs.mun.ca> wrote in message news:20020806172129.90200.qmail@pb1.pair.com... > > "Dan McCullough" <McWC@rocketmail.com> wrote in message > news:20020806165555.81543.qmail@web11808.mail.yahoo.com... > > I need to format numbers to look like dollars and cents. > > So if I have 1550 it needs to look like $15.50 if I have 50 then it needs > to look like $.50 > > Any thoughts. > > > > ===== > > -------------------------------------------------------- > > "Theres no such thing as a problem unless the servers are on fire!" > > > > > > __________________________________________________ > > Do You Yahoo!? > > Yahoo! Health - Feel better, live better > > http://health.yahoo.com > > Its kind of a long way of doing it but try tokenizing the whole > String 1550 hence returning and array containing > {1, 5, 5, 0} I believe the php method associated with this > is: token_get_all(myString); > > You can recreate a String using the last two array elements.. > > $decimals = "".arrayReturned[$lasPosition-1]."".array[$lastPosition]; > $foreFront = theOtherArrayElementsConcatenatedToFormAString; > > $myResult = "\$$foreFront$decimals"; > > Sorry that's the quickest way I could think of... > There are obviously less time consuming algorithms but my > brains not in thought mode this afternoon... > > Good luck... > > Spike... > > The number_format method suggested by Matt seems to be less verbose...

« previous php.general (#111409) next »