You are here: Re: Formatting Problem « PHP Programming Language « IT news, forums, messages
Re: Formatting Problem

Posted by Andy Hassall on 10/14/06 22:25

On Sat, 14 Oct 2006 17:58:26 -0400, "Smiley" <none@ofyourbusiness.com> wrote:

>In a program I'm creating, I'm trying to calculate a percentage. However,
>for some reason the calculation is only coming out to 1 decimal place, and I
>know there's more. Using this code:
>
>$gshare = $shareresults / $phenresults;
>echo "$shareresults / $phenresults = $gshare";
>
>I get the following output:
>
>3,340,000 / 5,180,000 = 0.6

They're not numbers, not with the commas in them. You can't divide formatted
strings.

When asked to treat strings as numbers, PHP reads as much of the data until it
stops matching basic numeric format, so you're actually getting 3/5 which is
0.6.

Remove the commas; only add them back in again when formatting them for
display.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

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

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