You are here: Re: Formatting of a number « PHP « IT news, forums, messages
Re: Formatting of a number

Posted by "Dan Baker" on 11/17/05 21:20

"Scott Parks" <scottaparks@gmail.com> wrote in message
news:95ECBB2B-8A48-4D28-A381-A1450C394D4B@gmail.com...
> Hi-
>
> I have a number that I am trying to format. It is data coming from a
> main frame and
> has 8 characters assigned to it (6 and two decimal places). I have
> zerofill set up in
> MySQL on this field and am working on the best way to display the number.
>
> Currently I have this:
>
> $sOutput = number_format(rtrim($sValue,'0') /100,2);
>
> What I am running into is this, I have a number in this field as:
> 3145900, using the above I will get: 314.59, which is wrong, it
> needs to be 3,145.90.
>
> Yet, if I have a number of: 749450, I get the result I am looking for
> of 749.45.
>
> I did not see a way to tell trim I only want one 0 cut?

Just convert the string into a number, and work with it as a number:

// first, convert the string into a number (assuming 3 decimals, as your
example shows)
$nValue = floatval($sValue) / 1000;
// then, format it
$sOutput = number_format($nNumber, 2);

DanB

 

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

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