By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

Where decimal part goes?

P: n/a
gs
Sorry if it will be second post, but after few hours I still can't see
my previous post.

I have problem with decimal parts on Solaris (PHP+ZendOptimizer). When I
get value from MySQL (or from text file - I have had the same), it is
loosing decimal parts.

For example, let say, that from MySQL I have $line[myvalue]=123.45
Then if I will do this:

echo $line[myvalue];
echo number_format($line[myvalue],2,".","");
echo 1*$line[myvalue];

I will recive this values:

123.45
123.00 => ?????
123

Does anybody know, where is the problem?
On some other instalation (on Windows and Linux) everything is O'K.

What is more interesting, when I compute this value - let say like this:

$newvalue=1.22*$something

I will have $newvalue eqal to 150,06, which is 1.22*123
And I can do everything with it without any problems.

Hope somebody could help me solving this problem,

Grzegorz Sowa
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
gs wrote:
Sorry if it will be second post, but after few hours I still can't see
my previous post.

I have problem with decimal parts on Solaris (PHP+ZendOptimizer). When I
get value from MySQL (or from text file - I have had the same), it is
loosing decimal parts.

For example, let say, that from MySQL I have $line[myvalue]=123.45
Then if I will do this:

echo $line[myvalue];
echo number_format($line[myvalue],2,".","");
echo 1*$line[myvalue];

I will recive this values:

123.45
123.00 => ?????
123

Does anybody know, where is the problem?
On some other instalation (on Windows and Linux) everything is O'K.

What is more interesting, when I compute this value - let say like this:

$newvalue=1.22*$something

I will have $newvalue eqal to 150,06, which is 1.22*123
And I can do everything with it without any problems.

Hope somebody could help me solving this problem,

Grzegorz Sowa


It looks like a bug in the numer_format routine. This works on an
OpenVMS PHP version 4.3.2 as well. In this case, you should go to the
PHP site and find the link to report bugs. You will need to most (if
not all) of the information from the output of phpinfo(). Make sure it
includes the OS version and patch level as well as the php version and
any fixes applied.

$line[myvalue]=123.45;
echo "$line[myvalue]\n";
echo number_format($line[myvalue],2,".","")."\n";
echo "$line[myvalue]\n";
echo 1*$line[myvalue]."\n";
echo "$line[myvalue]\n";

RESULT:

123.45
123.45
123.45
123.45
123.45

and just to make sure:

$line[myvalue]=123.45;
echo "$line[myvalue]\n";
$x = number_format($line[myvalue],2,".","");
echo "$x\n";
echo 1*$line[myvalue]."\n";
echo 1*$x."\n";
echo "$line[myvalue]\n";

123.45
123.45
123.45
123.45
123.45
Michael Austin.
Jul 17 '05 #2

P: n/a
gs
Dnia 2004-06-29 15:27, niejaki(a) Michael Austin wystukał(a) na klawiaturze:
It looks like a bug in the numer_format routine.


I suppose not in number_format. It is just where I have first seen it.
If I will do like this:

$something=191.2434;
$second=1*$something;
echo $second;

I will have 191 as output.

Byt if I will do like this:

$something=1912434/10000;
$second=$something;
echo $second;

it is 191.2434

So probably it is a bug, but I'm nearly sure that not with number_format.

Grzegorz Sowa
Jul 17 '05 #3

P: n/a
I'm going to vote user error here.

gs <gs@wirtual.NO.SPAM.com.pl> wrote in message news:<cb**********@korweta.task.gda.pl>...
Dnia 2004-06-29 15:27, niejaki(a) Michael Austin wystukał(a) na klawiaturze:
It looks like a bug in the numer_format routine.


I suppose not in number_format. It is just where I have first seen it.
If I will do like this:

$something=191.2434;
$second=1*$something;
echo $second;

I will have 191 as output.

Byt if I will do like this:

$something=1912434/10000;
$second=$something;
echo $second;

it is 191.2434

So probably it is a bug, but I'm nearly sure that not with number_format.

Grzegorz Sowa

Jul 17 '05 #4

P: n/a
(re-ordered: please don't top post)

I noticed that Message-ID:
<7a**************************@posting.google.com > from Brad Kent
contained the following:

gs <gs@wirtual.NO.SPAM.com.pl> wrote in message news:<cb**********@korweta.task.gda.pl>...
Dnia 2004-06-29 15:27, niejaki(a) Michael Austin wystukał(a) na klawiaturze:
So probably it is a bug, but I'm nearly sure that not with number_format.
I'm going to vote user error here.


Well I tried it and got error notices.
Try:

$line['myvalue']=123.45;
echo $line['myvalue']."\n";
echo number_format($line['myvalue'],2,".","")."\n";
echo "$line[myvalue]\n";
echo 1*$line['myvalue']."\n";
echo "$line[myvalue]\n";
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #5

P: n/a

"gs" <gs@wirtual.NO.SPAM.com.pl> wrote in message
news:cb**********@korweta.task.gda.pl...
Sorry if it will be second post, but after few hours I still can't see
my previous post.

I have problem with decimal parts on Solaris (PHP+ZendOptimizer). When I
get value from MySQL (or from text file - I have had the same), it is
loosing decimal parts.

For example, let say, that from MySQL I have $line[myvalue]=123.45
Then if I will do this:

echo $line[myvalue];
echo number_format($line[myvalue],2,".","");
echo 1*$line[myvalue];

I will recive this values:

123.45
123.00 => ?????
123

Does anybody know, where is the problem?
On some other instalation (on Windows and Linux) everything is O'K.

What is more interesting, when I compute this value - let say like this:

$newvalue=1.22*$something

I will have $newvalue eqal to 150,06, which is 1.22*123
And I can do everything with it without any problems.

Hope somebody could help me solving this problem,

Grzegorz Sowa


Sounds like a locale issue to me. PHP doesn't see 123.45 as 123 + 45/100
because the Polish notation is 123,45 (comma instead of period for the
decimal point). "123.45" thus get converted to 123.
Jul 17 '05 #6

P: n/a
"gs" <gs@wirtual.NO.SPAM.com.pl> wrote in message
news:cb**********@korweta.task.gda.pl...
Sorry if it will be second post, but after few hours I still can't see
my previous post.

I have problem with decimal parts on Solaris (PHP+ZendOptimizer). When I
get value from MySQL (or from text file - I have had the same), it is
loosing decimal parts.

For example, let say, that from MySQL I have $line[myvalue]=123.45
Then if I will do this:

echo $line[myvalue];
echo number_format($line[myvalue],2,".","");
echo 1*$line[myvalue];

I will recive this values:

123.45
123.00 => ?????
123

Does anybody know, where is the problem?
On some other instalation (on Windows and Linux) everything is O'K.

What is more interesting, when I compute this value - let say like this:

$newvalue=1.22*$something

I will have $newvalue eqal to 150,06, which is 1.22*123
And I can do everything with it without any problems.

Hope somebody could help me solving this problem,


Run this and see what it says:

print_r(localeconv());
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.