You are here: Re: number_format() question EASY « PHP Programming Language « IT news, forums, messages
Re: number_format() question EASY

Posted by Jerry Stuckle on 02/22/07 04:32

Anonymous wrote:
> Jerry Stuckle wrote:
>> rynTAU wrote:
>>> This is an easy question, I'm sure but I can't seem to figure it
>>> out.
>>>
>>> I'm trying to use the number_format() function to remove all decimal
>>> places from a number.
>>>
>>>
>>> $num = number_format($num, 0, '.', '');
>>>
>>> So if I have 23.34567 I want 23, and 45.8789 will return with 45.
>>> The problem is that the this function rounds the number off. so that
>>> 45.8789 returns 46 instead of 45.
>>>
>>> Is there another function? What should I be using.
>>>
>>> Thanks for your help.
>>>
>> $num = int($num);
>
> I would advise against type casting. It can produce strage results under
> some circumstances.
>
> He would be better of using $num = floor($num), that's what the function
> is here for.
>
> ceil() always rounds up, floor() always rounds down, round() rounds
> according to mathematical rules (down on .0 to .4, up on .5 to .9
>
> Bye!

And int() always truncates and returns an integer - which is exactly
what he wants. See the doc.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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