Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DoubleConverter

Converts arbitrary values into double 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

let value1 = DoubleConverter.toNullableDouble("ABC"); // Result: null
let value2 = DoubleConverter.toNullableDouble("123.456"); // Result: 123.456
let value3 = DoubleConverter.toNullableDouble(true); // Result: 1
let value4 = DoubleConverter.toNullableDouble(new Date()); // Result: current milliseconds

Hierarchy

  • DoubleConverter

Index

Methods

Static toDouble

  • toDouble(value: any): number
  • Converts value into doubles or returns 0 when conversion is not possible.

    see

    toDoubleWithDefault

    Parameters

    • value: any

      the value to convert.

    Returns number

    double value or 0 when conversion is not supported.

Static toDoubleWithDefault

  • toDoubleWithDefault(value: any, defaultValue?: number): number
  • Converts value into integer or returns default value when conversion is not possible.

    see

    toNullableDouble

    Parameters

    • value: any

      the value to convert.

    • Default value defaultValue: number = 0

      the default value.

    Returns number

    double value or default when conversion is not supported.

Static toNullableDouble

  • toNullableDouble(value: any): number
  • Converts value into doubles or returns null when conversion is not possible.

    Parameters

    • value: any

      the value to convert.

    Returns number

    double value or null when conversion is not supported.

Generated using TypeDoc