---
schema_version: "1"
id: 9740e1c1a2087e69e728f51221857a3c990e1224f06ffdd200c2d37f986a201d
title: Double Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_methods_system_double.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7f20bb8c61f42368d6594ecf60eae2f43d1c76d79f708842fc97c31efde36007
description: Contains methods for the Double primitive data type.Returns the String value for this Double using the locale of the context userReturns the Integer value of this Double by casting it to an Integer.Returns the Long value of this Double.Returns the closest Long to this Double value.Returns a Double that contains the value of the specified String. As in Java, the String is interpreted as representing a signed decimal.Converts the specified object to a Double value. Use this method to convert a history tracking field value or an object that represents a Double value.
---
# Double Class

Contains methods for the Double primitive data type.

## Namespace

[System](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_System.htm "The System namespace provides classes and methods for core Apex functionality.")

## Usage

For more information on Double, see [Double Data Type](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/langCon_apex_primitives.htm).

## Double Methods

The following are methods for Double.

- **[format()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm#apex_System_Double_format)**  
    Returns the String value for this Double using the locale of the context user
- **[intValue()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm#apex_System_Double_intValue)**  
    Returns the Integer value of this Double by casting it to an Integer.
- **[longValue()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm#apex_System_Double_longValue)**  
    Returns the Long value of this Double.
- **[round()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm#apex_System_Double_round)**  
    Returns the closest Long to this Double value.
- **[valueOf(stringToDouble)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm#apex_System_Double_valueOf)**  
    Returns a Double that contains the value of the specified String. As in Java, the String is interpreted as representing a signed decimal.
- **[valueOf(fieldValue)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_double.htm#apex_System_Double_valueOf_2)**  
    Converts the specified object to a Double value. Use this method to convert a history tracking field value or an object that represents a Double value.

### format()

Returns the String value for this Double using the locale of the context user

#### Signature

public String format()

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

#### Example

Double myDouble = 1261992;
Assert.areEqual('1,261,992', myDouble.format());

### intValue()

Returns the Integer value of this Double by casting it to an Integer.

#### Signature

public Integer intValue()

#### Return Value

Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Example

Double DD1 = double.valueOf('3.14159');
Integer value = DD1.intValue();
Assert.areEqual(3, value);

### longValue()

Returns the Long value of this Double.

#### Signature

public Long longValue()

#### Return Value

Type: [Long](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_long.htm#apex_methods_system_long "Contains methods for the Long primitive data type.")

#### Example

Double myDouble = 421994;
Long value = myDouble.longValue();
Assert.areEqual(421994, value);

### round()

Returns the closest Long to this Double value.

#### Signature

public Long round()

#### Return Value

Type: [Long](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_long.htm#apex_methods_system_long "Contains methods for the Long primitive data type.")

#### Example

Double D1 = 4.5;
Long L1 = D1.round();
Assert.areEqual(5, L1);

Double D2= 4.2;
Long L2= D2.round();
Assert.areEqual(4, L2);

Double D3= -4.7;
Long L3= D3.round();
Assert.areEqual(-5, L3);

### valueOf(stringToDouble)

Returns a Double that contains the value of the specified String. As in Java, the String is interpreted as representing a signed decimal.

#### Signature

public static Double valueOf(String stringToDouble)

#### Parameters

- **stringToDouble**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

#### Return Value

Type: [Double](#apex_methods_system_double "Contains methods for the Double primitive data type.")

#### Example

Double DD1 = double.valueOf('3.14159');

### valueOf(fieldValue)

Converts the specified object to a Double value. Use this method to convert a history tracking field value or an object that represents a Double value.

#### Signature

public static Double valueOf(Object fieldValue)

#### Parameters

- **fieldValue**:
    
    Type: Object

#### Return Value

Type: [Double](#apex_methods_system_double "Contains methods for the Double primitive data type.")

#### 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

List<AccountHistory> ahlist = 
  \[SELECT Field,OldValue,NewValue
   FROM AccountHistory WITH USER\_MODE\];
for(AccountHistory ah : ahlist) {
  System.debug('Field: ' + ah.Field);
  if (ah.field == 'NumberOfEmployees') {
    Double oldValue = 
      Double.valueOf(ah.OldValue);
    Double newValue = 
      Double.valueOf(ah.NewValue);
  }
}