Not every number in Apex is a whole number. For numbers with decimals, we can use the appropriately named Decimal
primitive datatype.
Decimal amount = 500.12; Decimal negativeBalance = -35.99; Decimal magicNumber = 3.14159;
Later when we retrieve currency fields from sObjects, we’ll use Decimals to keep track of them.
Decimals can be reassigned too!
Decimal amount = 500.12; amount = 450.65; amount = 320.99;
In Apex, the number of digits to the right of the decimal point is called scale. There are a ton of ways developers can manipulate and round decimal values. We won’t cover those in this lesson, but if you’re curious, here are the Salesforce docs.
That’s it! Pretty straightforward.