Closed GoogleCodeExporter closed 8 years ago
I've seen this problem before, and a quick solution is to cast the value to a
float
before passing it into the Money constructor. From what I've seen the number
only
gets corrupted once inside the SoapClient class, but I'll look into a more
holistic
solution to prevent this in the future.
Original comment by api.ekol...@gmail.com
on 6 Apr 2010 at 2:23
Thanks for the quick reply.
I have tried the suggested quick solution (float type casting), but that also
not
working.
Here is my updated code after applying float,
// Create bids.
$bids = new ManualCPCAdGroupCriterionBids();
$newMaxCpc = $newMaxCpc * 1000000;
$newMaxCpc = (float) $newMaxCpc;
$bids->maxCpc = new Bid(new Money($newMaxCpc));
$adGroupCriterion->bids = $bids;
I have also applied (float) in the main 'AdGroupCriterionService.php' file, but
that
didn't changed anything in the SOAP request.
...
public function __construct($microAmount = NULL, $ComparableValueType = NULL) {
if(get_parent_class('Money')) parent::__construct();
$this->microAmount = (float) $microAmount;
$this->ComparableValueType = $ComparableValueType;
}
...
I have tested this on Windows as well as on Linux machine.
Please let me know if you need any further details.
Original comment by tomnabie...@perfectstormmedia.com
on 6 Apr 2010 at 3:04
[deleted comment]
This is unusual but, when I am passing MaxCPC as '16.09', its working. So,
wondering
why the '16.08' causing the issue.
Original comment by tomnabie...@perfectstormmedia.com
on 6 Apr 2010 at 3:11
My understanding is that this has to do with the precision of floats in PHP:
http://php.net/manual/en/language.types.float.php
I'm not able to replicate this issue on my machine, but another user saw
success
casting to floats:
http://groups.google.com/group/adwords-
api/browse_thread/thread/f8e1a08b10d20079/8c32de9c3ef6e084?
show_docid=8c32de9c3ef6e084
Can you verify if the number is incorrect before being passed into SoapClient
or if
it is SoapClient that is converting it incorrectly?
Original comment by api.ekol...@gmail.com
on 6 Apr 2010 at 5:35
I have noted that the MaxCPC value '16080000' remain same till the
parent::__soapCall() statement (AdsSoapClient.php), after the soap call the soap
request showing it as '16079999'. This means the SoapClient converting it
incorrectly.
The data type for microAmount is Long and I think the SoapClient not converting
float
value correctly in this case. I have found similar issue posted by someone here,
http://bugs.php.net/bug.php?id=48717&thanks=6
Here is the output of var_dump($arguments); statement, taken just above the
parent::__soapCall().
array(1) {
[0]=>
object(AdGroupCriterionServiceMutate)#10 (1) {
["operations"]=>
array(1) {
[0]=>
object(AdGroupCriterionOperation)#9 (5) {
["operand"]=>
object(BiddableAdGroupCriterion)#4 (12) {
["userStatus"]=>
NULL
["systemServingStatus"]=>
NULL
["approvalStatus"]=>
NULL
["destinationUrl"]=>
NULL
["bids"]=>
object(ManualCPCAdGroupCriterionBids)#6 (5) {
["maxCpc"]=>
object(Bid)#7 (1) {
["amount"]=>
object(Money)#8 (3) {
["microAmount"]=>
float(16080000)
["ComparableValueType"]=>
NULL
["_parameterMap:private"]=>
array(1) {
["ComparableValue.Type"]=>
string(19) "ComparableValueType"
}
}
}
["bidSource"]=>
NULL
["positionPreferenceBids"]=>
NULL
["AdGroupCriterionBidsType"]=>
NULL
["_parameterMap:private"]=>
array(1) {
["AdGroupCriterionBids.Type"]=>
string(24) "AdGroupCriterionBidsType"
}
}
["firstPageCpc"]=>
NULL
["qualityInfo"]=>
NULL
["stats"]=>
NULL
["adGroupId"]=>
float(996459724)
["criterion"]=>
object(Criterion)#5 (3) {
["id"]=>
float(11281263724)
["CriterionType"]=>
NULL
["_parameterMap:private"]=>
array(1) {
["Criterion.Type"]=>
string(13) "CriterionType"
}
}
["AdGroupCriterionType"]=>
NULL
["_parameterMap:private"]=>
array(1) {
["AdGroupCriterion.Type"]=>
string(20) "AdGroupCriterionType"
}
}
["exemptionRequests"]=>
NULL
["operator"]=>
string(3) "SET"
["OperationType"]=>
NULL
["_parameterMap:private"]=>
array(1) {
["Operation.Type"]=>
string(13) "OperationType"
}
}
}
}
}
Original comment by tomnabie...@perfectstormmedia.com
on 7 Apr 2010 at 7:25
On my machine I'm actually seeing the value being output incorrect before it
gets
passed into the Money constructor. I've seen some success applying the round()
function to the value before passing it into the constructor though. Can you
try this
and let me know if it helps?
Original comment by api.ekol...@gmail.com
on 7 Apr 2010 at 1:31
I have tried String type casting on the MaxCPC value, before passing it into the
Money constructor and it works.
$newMaxCpc1 = (string) $newMaxCpc;
The updated code,
// Create bids.
$bids = new ManualCPCAdGroupCriterionBids();
$newMaxCpc = ($newMaxCpc * 1000000);
$newMaxCpc1 = (string) $newMaxCpc;
$bids->maxCpc = new Bid(new Money($newMaxCpc1));
$adGroupCriterion->bids = $bids;
I don't know how this worked, may be you can comment on this.
Thanks for your support.
Original comment by tomnabie...@perfectstormmedia.com
on 7 Apr 2010 at 2:53
There are know issues with using strings for large numerical values (see issue
#5).
Can you try using round instead and let me know if that works?
Original comment by api.ekol...@gmail.com
on 7 Apr 2010 at 3:00
Original comment by api.ekol...@gmail.com
on 8 Apr 2010 at 4:06
Original comment by api.ekol...@gmail.com
on 8 Apr 2010 at 4:06
Yes, I tried it with using round() function and it works as well. Here is the
updated
code,
// Create bids.
$bids = new ManualCPCAdGroupCriterionBids();
$newMaxCpc = ($newMaxCpc * 1000000);
$newMaxCpc1 = round($newMaxCpc);
$bids->maxCpc = new Bid(new Money($newMaxCpc1));
$adGroupCriterion->bids = $bids;
You can see that, I haven't applied any other options in the round() function.
The
round function returns result as a float value, but I am wondering what it makes
difference for MaxCPC value so that it works with round() and String type
casting and
not with Flaot type casting?
It helps if you throw some light on this issue.
Thanks,
: Janak Prajapati
Original comment by tomnabie...@perfectstormmedia.com
on 9 Apr 2010 at 5:20
The problem appears to be due to precision issues in PHP multiplication. Using
the round() function removed the extra digits and allowed for the correct value.
Original comment by api.ekol...@gmail.com
on 30 Jun 2010 at 6:29
Original issue reported on code.google.com by
tomnabie...@perfectstormmedia.com
on 6 Apr 2010 at 12:36