Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Double Class
Namespace
Usage
For more information on Double, see Double Data Type.
Double Methods
The following are methods for Double.
format()
Signature
public String format()
Return Value
Type: String
Example
1Double myDouble = 1261992;
2system.assertEquals('1,261,992', myDouble.format());intValue()
Signature
public Integer intValue()
Return Value
Type: Integer
Example
1Double DD1 = double.valueOf('3.14159');
2Integer value = DD1.intValue();
3system.assertEquals(value, 3);longValue()
Signature
public Long longValue()
Return Value
Type: Long
Example
1Double myDouble = 421994;
2Long value = myDouble.longValue();
3System.assertEquals(421994, value);round()
Signature
public Long round()
Return Value
Type: Long
Example
1Double D1 = 4.5;
2Long L1 = D1.round();
3System.assertEquals(5, L1);
4
5Double D2= 4.2;
6Long L2= D2.round();
7System.assertEquals(4, L2);
8
9Double D3= -4.7;
10Long L3= D3.round();
11System.assertEquals(-5, L3);valueOf(stringToDouble)
Signature
public static Double valueOf(String stringToDouble)
Parameters
-
stringToDouble:
Type: String
Return Value
Type: Double
Example
1Double DD1 = double.valueOf('3.14159');valueOf(fieldValue)
Signature
public static Double valueOf(Object fieldValue)
Parameters
-
fieldValue:
Type: Object
Return Value
Type: Double
Usage
Use this method with the OldValue or NewValue fields of history sObjects, such as AccountHistory, when the field type corresponds to a Double type, like a number field.
Example
1List<AccountHistory> ahlist =
2 [SELECT Field,OldValue,NewValue
3 FROM AccountHistory];
4for(AccountHistory ah : ahlist) {
5 System.debug('Field: ' + ah.Field);
6 if (ah.field == 'NumberOfEmployees') {
7 Double oldValue =
8 Double.valueOf(ah.OldValue);
9 Double newValue =
10 Double.valueOf(ah.NewValue);
11}