0

I am using a managed app. I am supposed to pass a decimal to a method. If I just send a decimal i.e. 22.0 it works. If I create a Decimal variable and pass it, it gives me an error:

Method does not exist or incorrect signature:

To be clear This works:

method(22.0);

This doesn't work

Decimal d;
method(d);

Can anyone explain why this is happening and if there is a workaround?

3
  • Are you giving d a value?
    – Dan Jones
    Feb 17, 2016 at 9:19
  • Can you pls share method(d). What is the type of this variable accept.. If it is manage package class still you can check the method It accept which type of arguments.
    – Ratan Paul
    Feb 17, 2016 at 9:24
  • Yes. I was just illustrating
    – Apex N-u-b
    Feb 17, 2016 at 9:25

2 Answers 2

1

If I will pass a decimal value, I would choose the Double data type.

Double d;

method(d);

4
  • I tried your suggestion by using a double but no change.
    – Apex N-u-b
    Feb 17, 2016 at 9:26
  • @ApexN-u-b Can you please post what is inside in your "method" ? This problem only occur when the method does not exist or the data pass to the method is not compatible with what is declared.
    – Hope
    Feb 17, 2016 at 9:28
  • 3
    It is a bad idea to get into the habit of mixing double and decimal, particularly if you are dealing with money where you want exact values that preserve and define a known number of decimal places.
    – Keith C
    Feb 17, 2016 at 9:31
  • ... but on reflection your change may be the solution if the signature of the method does use a double.
    – Keith C
    Feb 17, 2016 at 9:45
0

I fully agree what Keith has mentioned apart from that check if you are passing a string instead of decimal. You can use the following decimal method-

Decimal dx = Decimal.valueOf(d);
method(dx);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .