You need to sign in to do that
Don't have an account?
John King20
How to compare two decimals
Hi,
So I have a trigger to share an amount among Contacts when when Account is updated. I'm trying to evaluate where if the "split" amount is 0.00 to show to 3 decimal places rather than 2, but I can't get the code
if (shareEachContact == 0.00) to evaluate.
Basically if 0.02 was to be split among 3 contacts I'd want it split 0.007, 0.007, 0.006.
I have functionality that works for 2 decimnal places but want to cater for 3 in the above scenarion. Code below.
So I have a trigger to share an amount among Contacts when when Account is updated. I'm trying to evaluate where if the "split" amount is 0.00 to show to 3 decimal places rather than 2, but I can't get the code
if (shareEachContact == 0.00) to evaluate.
Basically if 0.02 was to be split among 3 contacts I'd want it split 0.007, 0.007, 0.006.
I have functionality that works for 2 decimnal places but want to cater for 3 in the above scenarion. Code below.
trigger updateShareFromTotal on Account (after update) { List<Contact> childContacts = new List<Contact>(); for(Account account : [SELECT Id, Total__c, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :Trigger.new]){ if(account.Total__c != Trigger.oldMap.get(account.id).Total__c){ Integer contactNumber = account.Contacts.size(); Decimal shareEachContact = 0; shareEachContact = account.Total__c.divide(contactNumber,2); if (shareEachContact == 0.00){ shareEachContact = account.Total__c.divide(contactNumber,3); } for (Integer i = 0; i < account.Contacts.size(); i++) { if (i == (contactNumber - 1)) { account.Contacts[i].Share__c = account.Total__c - (shareEachContact * (contactNumber - 1)); } else { account.Contacts[i].Share__c = shareEachContact; } childContacts.add(account.Contacts[i]); } } } update childContacts; }
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Thanks
if we have Total__c =0.02 and contact number = with the two decimal places, it's returning as 0.00 but the evaluation
Isn't returning as true, am I misunderstanding something? Essentially I want a way to check if it's less than 0.01 so I can go to 3 decimal places. I'm aware this may not but the most efficient way. New to this.
Thanks for any help