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
The new LearnerThe new Learner 

how to allow in the if loop if the decimal value is zero

Hi Experts,

I need to calculate two fieds which are decimals of place  0(1,0). now my requriment is that when Week__c/frequency__c output is 1.0,2.0 it should allow only 0 decimal place if not it should not allow in the loop. eg:output is 6.0 it should allow in the loop if the output is 6.1 it should not. can anyone help me pls.
thanks in advance
AshishkAshishk
Use UNNECESSARY rounding mode, create method which returns boolean, on exception it will return false.
Decimal example1 = 5.5;
Decimal example2 = 1.0;
system.assertEquals(1,
    example2.round(System.RoundingMode.UNNECESSARY));
try{
    example1.round(System.RoundingMode.UNNECESSARY);
} catch(Exception E) {
    system.assertEquals('System.MathException', E.getTypeName());
}

Hope this works.
Thanks
The new LearnerThe new Learner
HI Ashishk,

Below is my code snippit can you help me how to use above functionality. pls


              decimal week=Week__c;
              system.debug('!!!!!week'+week);
             decimal freuency= Frequency__c;
              system.debug('!!!!!freuency'+freuency);
              deciaml currentweek=week/frequency;
              system.debug('!!!!!currentweek'+currentweek);
              
             if(currentweek)
             {
                   // do something