Hello,
I have the following variables in my code:
$x =4;
$y= 123.4791187
When I multiply them I expect to get 493.9164748 but instead I get 492.
I've tried to do some conversions but it still didn't work..
Can any of you please advise what am I missing here?
Many thanks in advance,
Bob
Wrong result in multiplication
Moderator: General Moderators
-
bob_marely
- Forum Newbie
- Posts: 5
- Joined: Mon Jan 25, 2010 2:46 am
Re: Wrong result in multiplication
Code: Select all
❯ php -r 'var_dump(4*123.4791187);'
float(493.9164748)
-
bob_marely
- Forum Newbie
- Posts: 5
- Joined: Mon Jan 25, 2010 2:46 am
Re: Wrong result in multiplication
thanks for your answer!
It doesn't work with or without the conversions. I only tried the conversions as a solution and I removed it when I realized it doesn't work.
Any other sugesstions?
It doesn't work with or without the conversions. I only tried the conversions as a solution and I removed it when I realized it doesn't work.
Any other sugesstions?
Re: Wrong result in multiplication
Try adding a decimal to the first number.
Code: Select all
$x = 4.0;
$y = 123.4791187;
echo ($x * $y);
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Wrong result in multiplication
Code: Select all
$x = 4;
$y = 123.4791187;
$z = $x * $y;
echo $z;
// 493.9164748
Paste the code that you use for the 'multiplication'bob_marely wrote:Can any of you please advise what am I missing here?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering