function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
baseball123baseball123 

Glitch of Setting Currency Value

I'm experiencing a very weird situation that random number populated to Payment_Schedule__c.Amount_to_be_paid__c. This is a currency field: Currency(16, 2). For example, I System.out.println the value before set to this field: 55.20666666666665. So 55.21 should be expected to be updated to this field but sometime 887.21 is populated in this field. The following is the code. I print out the value rigth before update and in the log file it shows 55.20666666666665 but after update 887.21 is the value being populated. Most of the time it populates the correct value but out of blue the wrong value is populated. It absolutely puzzles me. Anyone can give me a hint, it will be greatly appreciated. 

 

 

 

Payment_Schedule__c update_PS= new Payment_Schedule__c();

update_PS.setId(originalPS.getId());

double newPaymentAmount = 0;
newPaymentAmount = originalPS.getAmount_to_be_paid__c() + diffAmount;

update_PS.setAmount_to_be_paid__c(newPaymentAmount); 
System.out.println("updatePS.getAmount_to_be_paid__c() is " + update_PS.getAmount_to_be_paid__c()); 

Payment_Schedule__c[] ps_Updates = new Payment_Schedule__c[1];
ps_Updates[0] = update_PS;
try {
SaveResult[] saveResults = connection.update(ps_Updates);
//for (SaveResult saveResult : saveResults) {
for (int j=0; j<saveResults.length; j++) {

if (saveResults[j].isSuccess()) {
Logger.log("Successfully updated Original Payment Schedule ID: " +
saveResults[j].getId(), true);
System.out.println("Successfully updated Original Payment Schedule ID: " +
saveResults[j].getId());

} else {
// Handle the errors.
// We just print the first error out for sample purposes.
Error[] errors = saveResults[j].getErrors();
if (errors.length > 0) {
Logger.log("Error: could not update " +
"Original Payment Schedule ID " + saveResults[j].getId() + ".", true);

Logger.log("\tThe error reported was: (" +
errors[0].getStatusCode() + ") " +
errors[0].getMessage() + ".", true);

}
}
break;
}

} catch (ConnectionException ce) {
ce.printStackTrace();
}