Reply to Re: Stop PHP 5 from Rounding

Your name:

Reply:


Posted by tim on 05/29/06 04:17

Jackson Peebles wrote:
> Hey everyone!
> I am trying to create a calculator that calculates a
> diameter * pi, and I got it, but I can't stop it from rounding to a few
> digits, which is very annoying.

Hi there

Floating point numbers are usually only accurate to about 14 decimal
places and only close approximations of the number you expected.

http://uk.php.net/manual/en/language.types.float.php
http://docs.sun.com/source/806-3568/ncg_goldberg.html

>I'm looking at calculating like ten thousand digits and printing all of them

Check out the bcmath library, it is accurate to any number of digits
you need but it comes at the expense of speed.

The user comments say the last few digits are approximate so if you
need accuracy to a 100 digits use 104 digits and ignore the last 4...

http://uk.php.net/manual/en/ref.bc.php

Tim

[Back to original 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

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