# Abstract Quantity

`AbstractQuantity` provides additional methods to convert values directly into a target unit. They are more useful as meta-data converted to the application's internal representation (typically a double primitive type in some fixed units) before computation or further processing begin. For this purpose `AbstractQuantity` provides the `longValue(Unit)` and `doubleValue(Unit)` convenience methods.

For example the `doubleValue(Unit)` method is equivalent to the following:

```
public double doubleValue(Unit<Q> unit) {
   return getUnit().getConverterTo(unit).convert(getValue().doubleValue());
}
```

With such method, user code like below are slightly easier to write:

```java
double calculateTravelTimeInSeconds(AbstractQuantity<Length> distance, AbstractQuantity<Speed> speed) {
   return distance.doubleValue(METRE) /
          speed.doubleValue(METRE_PER_SECOND);
}
```

Note that an equivalent operation can also be done using the Quantity.divide(Quantity) method.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unitsofmeasurement.gitbook.io/unit-ri-userguide/abstract-base-classes/abstract-quantity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
