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
Aphinya PhansawangAphinya Phansawang 

intValue() method return invalid value for some input

Hi,

I try to convert decimal value: 2152412850.50 to integer by using intValue() method but this method return -2142554446.
It happen for some value only. Is there any way to fix this problem or work around to convert decimal value to integer.

Thanks,
Best Answer chosen by Aphinya Phansawang
BalajiRanganathanBalajiRanganathan
Integer - A 32-bit number that does not include a decimal point. Integers have a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647.

Since your input is out of range, you get different value.

To resolve the issue, you have to use Long
Decimal decimalValue = 2152412850.50;
Long value = decimalValue.longValue();
System.debug('out: ' + value);

 

All Answers

BalajiRanganathanBalajiRanganathan
Integer - A 32-bit number that does not include a decimal point. Integers have a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647.

Since your input is out of range, you get different value.

To resolve the issue, you have to use Long
Decimal decimalValue = 2152412850.50;
Long value = decimalValue.longValue();
System.debug('out: ' + value);

 
This was selected as the best answer
Aphinya PhansawangAphinya Phansawang
Big thanks BalajiRanganathan ;-)
Daniel MadhureDaniel Madhure
Hey Balaji,

Thanks for this valuble input.it help me to resolve my issue.