round():
Returns the rounded approximation of this Decimal. The number is rounded to zero decimal places using half-even rounding mode, that is, it rounds towards the “nearest neighbor” unless both neighbors are equidistant, in which case, this mode rounds towards the even neighbor.
Apex Code
Decimal d1 = 3.48;
System.debug(d1.round());
scale():
Returns the scale of the Decimal, that is, the number of decimal places.
Apex Code
Decimal d1 = 9.27400968;
System.debug(d1.scale());
intValue():
Returns the Integer value of this Decimal.
Apex Code
Decimal d1 = 12.12;
System.debug(d1.intValue());
format():
Returns the String value of this Decimal using the locale of the context user.
Apex Code
Decimal d1 = 12345.6789;
System.debug(d1.format());
Execution Log
DEBUG | 12,345.679
abs():
Returns the absolute value of the Decimal.
Apex Code
Decimal d1 = -0.004;
System.debug(d1.abs());
Execution Log
DEBUG | 0.004
setScale():
Returns the Decimal scaled to the specified number of decimal places, using half-even rounding, if necessary. Half-even rounding mode rounds toward the “nearest neighbor.” If both neighbors are equidistant, the number is rounded toward the even neighbor.
Apex Code
Decimal d = 12.98767655;
d = d.setScale(2);
System.debug(d);
Execution Log
DEBUG | 12.99
valueOf():
Type 1: Returns a Decimal that contains the value of the specified String.
Apex Code
String text = '12.4567';
Decimal d1 = Decimal.valueOf(text);
System.debug(d1);
Execution Log
DEBUG | 12.4567
Type 2: Returns a Decimal that contains the value of the specified Long.
Apex Code
Long l = 121323342354L;
Decimal d1 = Decimal.valueOf(l);
System.debug(d1);
Execution Log
DEBUG | 121323342354
Type 3: Returns a Decimal that contains the value of the specified Double.
Apex Code
Double d = 12.04;
Decimal d1 = Decimal.valueOf(d);
System.debug(d1);
Execution Log
DEBUG | 12.04
Mastered by 203 users.