You are here: Re: decimal formatting « All PHP « IT news, forums, messages
Re: decimal formatting

Posted by Kim Andr Aker on 09/12/06 01:45

aaron.reese@tiscali.co.uk wrote:
> [top-posting fixed]
> Kim André Akerø wrote:
> > wesley@ispace.co.za wrote:
> >
> > > Hi all
> > > I have a floating point number stored in a variable. i want to
> > > round that number off to two places and store it in a variable.
> > > Does anyone know how to do that?
> > > I know that i can use the printf to display the number to 2
> > > decimal places. but i want to store that number in a vaiable.
> >
> > How about this:
> > $value = 3.1415926535897932384626433832795;
> > $value = round($value, 2);
> >
> > http://no.php.net/round
>
> multiply by 100
> convert to integer (drop decimals)
> divide by 100

Why make it difficult when round() will do just that in a single shot?

--
Kim André Akerø
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)

 

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

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