Package org.pipservices3.commons.convert
Class DoubleConverter
java.lang.Object
org.pipservices3.commons.convert.DoubleConverter
Converts arbitrary values into double.
Converts using extended conversion rules:
- Strings are converted to double values
- DateTime: total number of milliseconds since unix epoсh
- Boolean: 1 for true and 0 for false
### Example ###
double value1 = DoubleConverter.toNullableDouble("ABC"); // Result: null
double value2 = DoubleConverter.toNullableDouble("123.456"); // Result: 123.456
double value3 = DoubleConverter.toNullableDouble(true); // Result: 1
double value4 = DoubleConverter.toNullableDouble(new Date()); // Result: current milliseconds
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
Converts value into doubles or returns 0 when conversion is not possible.static double
toDoubleWithDefault
(Object value, double defaultValue) Converts value into doubles or returns default value when conversion is not possible.static Double
toNullableDouble
(Object value) Converts value into doubles or returns null when conversion is not possible.
-
Constructor Details
-
DoubleConverter
public DoubleConverter()
-
-
Method Details
-
toNullableDouble
Converts value into doubles or returns null when conversion is not possible.- Parameters:
value
- the value to convert.- Returns:
- double value or null when conversion is not supported.
-
toDouble
Converts value into doubles or returns 0 when conversion is not possible.- Parameters:
value
- the value to convert.- Returns:
- double value or 0 when conversion is not supported.
- See Also:
-
toDoubleWithDefault
Converts value into doubles or returns default value when conversion is not possible.- Parameters:
value
- the value to convert.defaultValue
- the default value.- Returns:
- double value or default when conversion is not supported.
- See Also:
-