(0.7/0.001)%10 does not return 0

0 votes

The code snippet is as follows...

$orderAmount = $_POST['orderAmount'];
$adUnitPrice = 0.001;
if((($orderAmount/$adUnitPrice) % 10) == 0)
    $standardPayment = true;
else
    $standardPayment = false;
When I am passing $orderAmount as 0.6 or 0.8, I get the expected return of $standardPayment = true. But, when I am passing $orderAmount as 0.7, I get the unexpected return of $standardPayment = false
I dont understand why this is happening. Need help regarding this.
Aug 31, 2018 in Blockchain by slayer
• 29,170 points
38 views

1 answer to this question.

0 votes

bcmath module can help you

bcmod(bcdiv("0.7", "0.001"), "10"); // returns 0

in your code

$orderAmount = $_POST['orderAmount'];
$adUnitPrice = 0.001;
if(bcmod(bcdiv($orderAmount, $adUnitPrice), 10) == 0) {
    $standardPayment = true;
} else {
    $standardPayment = false;
}

or even

$standardPayment = (bcmod(bcdiv($orderAmount, $adUnitPrice), 10) == 0);

you can check on command line with php -m and look if has the module or write a file with the follow

<?php phpinfo(); ?>
answered Aug 31, 2018 by digger
• 26,550 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
2 answers

Why does not India consider Bitcoin as a legal tender?

to be specific there are few logical ...READ MORE

answered Jul 2, 2018 in Blockchain by Priyaj
• 56,900 points
68 views
0 votes
1 answer
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,550 points
3,596 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
153 views
0 votes
1 answer
0 votes
1 answer

Web3 1.0: What does `web3.eth.call(tx)` return for a contract creation?

The returned bytestring is the deployedBytecode of the contract, ...READ MORE

answered Sep 17, 2018 in Blockchain by digger
• 26,550 points
78 views