Int

public extension Int

This bundle of extensions provides utility functions for converting between different numeric representations and obtaining string representations. The toDouble function converts an integer to a double, centsToDollars converts a dollar amount in cents to dollars, and toString converts any supported type to its string representation. These functions enhance the versatility of working with numeric and string data in Swift.

  • Converts the given integer to a double.

    Example:

      let integerNumber = 42
      let doubleValue = integerNumber.toDouble()
      print(doubleValue) // Output: 42.0
    

    Declaration

    Swift

    func toDouble() -> Double

    Return Value

    A double value representing the converted integer.

  • Converts the given dollar amount in cents to dollars.

    Example:

      let centsAmount = 1500
      let dollarsValue = centsAmount.centsToDollars()
      print(dollarsValue) // Output: 15.0
    

    Declaration

    Swift

    func centsToDollars() -> Double

    Return Value

    A double value representing the dollar amount.

  • Converts the value to its string representation.

    Example:

      let number = 123
      let stringValue = number.toString()
      print(stringValue) // Output: "123"
    

    Declaration

    Swift

    func toString() -> String

    Return Value

    A string representation of the value.

  • Converts a Integer to a Bool Value

    Example:

      let testBool = 1.toBool() // true
    

    Declaration

    Swift

    func toBool() -> Bool