Class: Toybox.Lang.Float

Inherits:
Toybox.Lang.Object show all

Overview

Floats are 32-bit floating point values.

By default, decimal values in Monkey C are Floats.

Since:

API Level 1.0.0

Instance Method Summary collapse

Instance Method Details

abs() as Lang.Float

Get the absolute value of a Float.

Returns:

Since:

API Level 1.0.0

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

Format a Float 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 Float to a Double.

Returns:

Since:

API Level 1.0.0

toFloat() as Lang.Float

Convert a Float to a Float.

Returns:

  • Lang.Float

    A Float representation of the Float

Since:

API Level 1.0.0

toLong() as Lang.Long

Convert a Float to a Long.

Returns:

  • Lang.Long

    A Long representation of the Float

Since:

API Level 1.0.0

toNumber() as Lang.Number

Convert a Float to a Number.

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

Returns:

Since:

API Level 1.0.0


Generated Jul 7, 2021 10:36:25 AM