pip_services3_commons.convert.FloatConverter module

pip_services3_commons.convert.FloatConverter

Float conversion utilities

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_commons.convert.FloatConverter.FloatConverter

Bases: object

Converts arbitrary values into float 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: .. code-block:: python

value1 = FloatConverter.to_nullable_float(“ABC”) # Result: None value2 = FloatConverter.to_nullable_float(“123.456”) # Result: 123.456 value3 = FloatConverter.to_nullable_float(true) # Result: 1 value4 = FloatConverter.to_nullable_float(datetime.datetime.now()) # Result: current milliseconds

static to_float(value: Any)float

Converts args into float or returns 0 when conversion is not possible.

Parameters

value – the args to convert.

Returns

float args or 0 when conversion is not supported.

static to_float_with_default(value: Any, default_value: float)float

Converts args into float or returns default when conversion is not possible.

Parameters
  • value – the args to convert.

  • default_value – the default args.

Returns

float args or default args when conversion is not supported.

static to_nullable_float(value: Any) → Optional[float, None]

Converts args into float or returns null when conversion is not possible.

Parameters

value – the args to convert.

Returns

float args or null when conversion is not supported.