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,370 points
857 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,740 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 3, 2018 in Blockchain by Priyaj
• 58,100 points
817 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,740 points
45,042 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
1,882 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
806 views
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,740 points
1,179 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP