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
Pranav HP 9Pranav HP 9 

Double data type not accepted!!!Help me plz

Hi ,
I have wriiten a code which is to add &sub 2 numbers...When I use data type as int I am able to run the code successfully.However,when I use data type double I am getting an error which says "Method does not exist or incorrect signature: [mathamatics].resultofadd(Decimal, Decimal)".Below is my code:
public with sharing class mathamatics
{
public double resultofadd{get;set;}
public double  resultofsub{get;set;}

public mathamatics(){


}

public double  resultofadd(double  a,double  b)
{
double  z=a+b;

System.debug(z);
return z;
}
public double  resultofsub(double  a,double  b)
{
double  z=a-b;
System.debug(z);
return z;

}
In asynchronous window:
 mathamatics d=new  mathamatics(); 
d.resultofadd(6.12,4.11);
d.resultofsub(6.022,4.122);

Pls help 

 
Best Answer chosen by Pranav HP 9
GauravGargGauravGarg
Hi Pranav,

Please use below code:
public with sharing class mathamatics
{
    public double resultofadd1{get;set;}
    public double resultofsub1{get;set;}
    
    public mathamatics(){ 
    }

    public decimal resultofadd(decimal  a,decimal  b)
    {
        decimal z=a+b;
        System.debug(z);
        return z;
	}
    public decimal  resultofsub(decimal  a,decimal  b)
    {
        decimal z=a-b;
        System.debug(z);
        return z;
    } 
}



Thanks
Gaurav

All Answers

GauravGargGauravGarg
Hi Pranav,

Please use below code:
public with sharing class mathamatics
{
    public double resultofadd1{get;set;}
    public double resultofsub1{get;set;}
    
    public mathamatics(){ 
    }

    public decimal resultofadd(decimal  a,decimal  b)
    {
        decimal z=a+b;
        System.debug(z);
        return z;
	}
    public decimal  resultofsub(decimal  a,decimal  b)
    {
        decimal z=a-b;
        System.debug(z);
        return z;
    } 
}



Thanks
Gaurav
This was selected as the best answer
GauravGargGauravGarg
Hi Pranav,

could you please try above code and let me know if you still face issues on it. 
Pranav HP 9Pranav HP 9
Hi Gaurav....Thanks for the solution its working fine!!!!!!!!Sorry for delay in response!!!!!! Thanks and Regards Pranav
GauravGargGauravGarg

Hi Pranav,

please select it as best answer then. 
 

Thanks,

Gaurav

Pranav HP 9Pranav HP 9
ok sure!!!!!!!!