You are here: Re: PHP round() bug? « PHP Programming Language « IT news, forums, messages
Re: PHP round() bug?

Posted by Chris Hope on 05/25/05 01:39

db_guy wrote:

> <?
> $a=1.5345493;
>
> $b=round($a,2);
>
> echo "b: ".$b;
> ?>
>
> This code should return "b: 1.54", but instead returns "b: 1.53". Can
> anyone else confirm this?
>
> Also, does anyone have a way around this issue?

Why should it return 1.54?

1.5345493 rounded to two decimal places *should* give 1.53

The numbers 0 to 4 are rounded down, and 5 to 9 are rounded up.

The third number after the decimal place is a 4 which would indicate the
number should be rounded down, leaving you with 1.53.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

 

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

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