Options
All
  • Public
  • Public/Protected
  • All
Menu

Class IntegerConverter

Converts arbitrary values into integers using extended conversion rules:

  • Strings are converted to floats, then to integers
  • DateTime: total number of milliseconds since unix epoсh
  • Boolean: 1 for true and 0 for false

Example

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

Hierarchy

  • IntegerConverter

Index

Methods

Static toInteger

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

    see

    LongConverter.toLong

    see

    LongConverter.toLongWithDefault

    Parameters

    • value: any

      the value to convert.

    Returns number

    integer value or 0 when conversion is not supported.

Static toIntegerWithDefault

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

    see

    LongConverter.toLongWithDefault

    see

    LongConverter.toNullableLong

    Parameters

    • value: any

      the value to convert.

    • defaultValue: number

      the default value.

    Returns number

    integer value or default when conversion is not supported.

Static toNullableInteger

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

    see

    LongConverter.toNullableLong

    Parameters

    • value: any

      the value to convert.

    Returns number

    integer value or null when conversion is not supported.

Generated using TypeDoc