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
jameskCAjameskCA 

Apex method treats numbers without decimals as integers when doing math?

I have a very basic method:
public decimal inverterPerformanceFactor(String inverter){
        if(inverter.contains('Enphase')){
            return (104.00/100.00);
            
        }
        else{ return (102.00/100.00);}
    }
Without the decimal places, e.g. 102.00 vs 100, the method would always return 1.  I'm just curious why that is?  Should I always specify a decimal value when doing math in apex?  
 
PavanKPavanK
You should use
public Decimal divide(Decimal divisor, Integer scale)


Example is
 
Decimal decimalNumber = 19;
Decimal result = decimalNumber.divide(100, 3);
System.assertEquals(0.190, result);

Please mark as best answer if repsonse helped you.

Thanks