In Apex, the Decimal data type is used to represent numbers that include a fractional part. It is suitable for financial calculations and any other context where precision is important.
// Declaring and initializing a Decimal
Decimal price = 19.99;
// Performing arithmetic with Decimals
Decimal taxRate = 0.08;
Decimal tax = price * taxRate;
Decimal totalPrice = price + tax;
System.debug('Total price: ' + totalPrice);
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create account