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
Somasundaram SubramanianSomasundaram Subramanian 

currency field comparison

i have a currecny field type 
how to compare the value of field is >0 using apex class please suggets
SubratSubrat (Salesforce Developers) 
Hello ,

To compare if a currency field value is greater than zero using Apex, you can simply use the greater than operator (>) in an if statement. Here's an example:
Decimal currencyFieldValue = myObject.CurrencyField__c;

if (currencyFieldValue > 0) {
    // Perform your logic when the currency field value is greater than zero
    System.debug('Currency value is greater than zero.');
} else {
    // Perform your logic when the currency field value is not greater than zero
    System.debug('Currency value is not greater than zero.');
}
In the above code, myObject represents the object that contains the currency field (CurrencyField__c). We store the value of the currency field in the currencyFieldValue variable.

We then use an if statement to compare the currencyFieldValue with zero using the greater than (>) operator. If the value is greater than zero, the logic within the if block will be executed. Otherwise, the logic within the else block will be executed.

If this helps , please mark this as Best Answer.
Thank you.
Somasundaram SubramanianSomasundaram Subramanian
Hi
    But its not working as expected if currency is USD then its skip even currency value shows USD0 but for EUR0 it works fine, is this issue due to currency field type in back end i checked the value it shows 0.00