Class: Toybox.Lang.Double

Inherits:
Toybox.Lang.Object show all

Overview

Double represents a 64-bit floating point number.

To use a double in Monkey C add 'd' to the end of the number.

Example:

var e = 2.718281828459045d;

Since:

API Level 1.0.0

Instance Method Summary collapse

Instance Method Details

abs() as Lang.Double

Get the absolute value of a Double.

Returns:

Since:

API Level 1.0.0

compareTo(other as Lang.Object) as Lang.Number

Compare the numeric value of self to some other numeric value. NaN is

  considered greater than all numbers and equal to itself.

Parameters:

  • other(Lang.Object)

    The right hand side of a comparison.

Returns:

  • Lang.Number

    A negative value if self is less than other, zero if the objects are equivalent, and a positive value if self is greater than other.

Since:

API Level 5.0.0

Throws:

equals(other as Lang.Object or Null) as Lang.Boolean

Test if an Object instance is equal to another instance of an Object.

Parameters:

  • other(Lang.Object)

    The Object to test against

Returns:

  • Lang.Boolean

    true if the Objects are equal, otherwise false

Since:

API Level 1.3.0

format(format as Lang.String) as Lang.String

Format a Double using a formatting String.

The formatting string is similar to that available in printf from the C stdio library, though the length option is not available:

    "%[flags][width][.precision]specifier"
specifiers
  • d or i - signed decimal integer

  • e - scientific notation (mantissa/exponent) using 'e' character

  • E - scientific notation (mantissa/exponent) using 'E' character

  • f - decimal floating point

  • o - signed octal

  • u - unsigned decimal integer

  • x - unsigned hexadecimal integer

  • X - unsigned hexadecimal integer (capital letters)

flags
  • + - Prepends the result with a plus or minus sign ('+' or '-'), including positive numbers. By default, only negative numbers are preceded with a '-' sign.

  • 0 - Left-pads the number with zeros (0) instead of spaces, where padding is specified (see width sub-specifier).

width

supports only numbers (* is not supported)

.precision

supports only numbers (* is not supported)

Returns:

Since:

API Level 1.0.0

toDouble() as Lang.Double

Convert a Double to a Double.

Returns:

  • Lang.Double

    A Double representation of the Double

Since:

API Level 1.0.0

toFloat() as Lang.Float

Convert a Double to a Float.

Returns:

  • Lang.Float

    A Float representation of the Double

Since:

API Level 1.0.0

toLong() as Lang.Long

Convert a Double to a Long.

Returns:

  • Lang.Long

    A Long representation of the Double

Since:

API Level 1.0.0

toNumber() as Lang.Number

Convert a Double to a Number.

The Double value will be rounded toward 0 upon conversion. For example, 6.8 becomes 6 and -5.7 becomes -5.

Returns:

  • Lang.Number

    A Number representation of the Double

Since:

API Level 1.0.0

toString() as Lang.String

Convert a Double to a String.

Returns:

  • Lang.String

    The String representation of the Double

Since:

API Level 1.0.0


Generated Sep 23, 2024, 3:32:49 PM