Re: Money formatting

From: Date: Tue, 06 Aug 2002 17:15:17 +0000
Subject: Re: Money formatting
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111408@lists.php.net to get a copy of this message
"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...

« previous php.general (#111408) next »