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