+ Start a Discussion
KierenJamesonKierenJameson 

When would I use double vs decimal?

I'm trying to find a plain english example of when to use double vs decimal as a data type. I understand that by default all currencies are decimal and I've looked at a bunch of the online documentation (and the apex workbook which has pretty good definitions), but it's still not clear to me. 

Can anyone give me some examples?  Thanks! Kieren
Best Answer chosen by KierenJameson
PratikPratik (Salesforce Developers) 
Hi Kiren,

As you mentioned, decimal are used in currencied by deafult, while programming you can use double to store lage value in the variable.
(A 64-bit number that includes a decimal point. Doubles have a minimum value of -263 and a maximum value of 263-1.)  
This is really an interesting question. I will post here if i found any example or will try to create one. 

Thanks,
Pratik

All Answers

PratikPratik (Salesforce Developers) 
Hi Kiren,

As you mentioned, decimal are used in currencied by deafult, while programming you can use double to store lage value in the variable.
(A 64-bit number that includes a decimal point. Doubles have a minimum value of -263 and a maximum value of 263-1.)  
This is really an interesting question. I will post here if i found any example or will try to create one. 

Thanks,
Pratik
This was selected as the best answer
KierenJamesonKierenJameson
Hey Pratik,

Thanks for this. After a bunch more research, I think the following is true...can you (or someone else) confirm:

Decimals - A number that includes a decimal point. Decimal is an arbitrary precision number. In Apex, currency fields are automatically assigned the type Decimal. Also Decimal has a lot of built-in methods and rounding options, so it’s helpful to use this instead of double.

Double - Also a number that includes a decimal point. From –massive to massive (e.g., they have the same min and max as the Long data type

Is that the main reason why you'd use decimal, because it has better methods and rounding options?

Thanks again!
Kieren
PratikPratik (Salesforce Developers) 
Hi Kieren,

Thanks for the sharing details.
I feel the rounding option with decimal more logical as far as currency field is concerned.
In the documentation also decimal is stressed with currency field.  You findings are correct.

Thanks,
Pratik
PratikPratik (Salesforce Developers) 
Glad it helped! Thanks for inputs too!

Thanks,
Pratik