Class DoubleConverter

java.lang.Object
org.pipservices3.commons.convert.DoubleConverter

public class DoubleConverter extends Object
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 Details

    • DoubleConverter

      public DoubleConverter()
  • Method Details

    • toNullableDouble

      public static Double toNullableDouble(Object value)
      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

      public static double toDouble(Object value)
      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

      public static double toDoubleWithDefault(Object value, double defaultValue)
      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: