Formatting Problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

That's wrong.  How can I correct this?  

Re: Formatting Problem

Quoted text here. Click to load it

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

 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

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

Andy Hassall :: :: :: disk and FTP usage analysis tool

Re: Formatting Problem

if you're really lazy:

$gshare = str_replace(',','',$shareresults) /

Site Timeline