Salesforce: Convert decimal value to integer using apex

If we convert decimal into integer like below code, it will compile without a problem, but at the time of execution, an error will occur.

Decimal mydecval = 15.0;
Integer myintval = Integer.valueOf(mydecval);

So, we should always use decimalvariable.intValue() to convert decimal value into integer.
Here is sample code:

Decimal mydecval = 15.0;
Integer myintval = mydecval.intValue();

  • ALIN PIERO JAVIER CRUZ

    But If I wanna to convert the variable in same Salesforce, How to convert?. Salesforce only has Number. So I will try it to print.

  • Renzo Manuel Gómez Césare

    I will try it