tags:

views:

983

answers:

3

I'm trying to do an echo of a variable containing 1400000. so there is written: echo round(1400000); this gives 1,4E+6 instead of the full number. Anybody an idea on how to display it fully?

+2  A: 

Possibly related to this bug report, so you could try

printf("%d", $myvar);
Paul Dixon
+2  A: 

Related to your question, I also came across this comment on the PHP website.

PHP switches from the standard decimal notation to exponential notation for certain "special" floats. You can see a partial list of such "special" values with this:

for( $tmp = 0, $i = 0; $i < 100; $i++ ) 
{
    $tmp += 100000;
    echo round($tmp),"\n"; 
}

So, if you add two floats, end up with a "special" value, e.g. 1.2E+6, then put that value unmodified into an update query to store the value in a decimal column, say, you will likely get a failed transaction, since the database will see "1.2E+6" as varchar data, not decimal. Likewise, you will likely get an XSD validation error if you put the value into xml.

I have to be honest: this is one of the strangest things I have seen in any language in over 20 years of coding, and it is a colossal pain to work around.

It seems there has not been a "real" fix yet, but judging from the comments in the bug report Paul Dixon referered to earlier, his solution seems to work.

Aron Rotteveel
+1  A: 

great work, thx for the answer. It seems that round was the pain in the ass. I changed it with number_format() and this does the job just fine. Thx Aron and Paul for the answers

Kennethvr
If you're happy with the answers, you might considering marking one as "Accepted"
Dominic Rodger
... and considering commenting the answer rather than adding new answer as a comment
shfx
ok, i m new, but will keep that in mind
Kennethvr
hmmm someone needs to edit this so the right person gets points here :p
bobwah