Class: Toybox::Lang::Number

Inherits:
Object
  • Object
show all

Overview

Number represents a 32-bit signed integer.

Since:

  • 1.0.0

Instance Method Summary collapse

Methods inherited from Object

equals, hashCode, method, toString, weak

Instance Method Details

absToybox::Lang::Number

Get the absolute value of a Number.

Returns:

Since:

  • 1.0.0


6294
6295
# File 'Monkeybrains.rb', line 6294

def abs()
end

format(format) ⇒ Toybox::Lang::String

Format a Number 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)

Examples:

Formatting time with leading zeros

// Format the time to display "08:03:15"
using Toybox.Lang;
var hours = 8;
var minutes = 3;
var seconds = 15;
var myTime = Lang.format(
    "$1$:$2$:$3$",
    [hours.format("%02d"), minutes.format("%02d"), seconds.format("%02d")]
);

Returns:

See Also:

Since:

  • 1.0.0


6355
6356
# File 'Monkeybrains.rb', line 6355

def format(format)
end

toCharToybox::Lang::Char

Convert a Number to a Char.

Returns:

Since:

  • 1.3.0


6361
6362
# File 'Monkeybrains.rb', line 6361

def toChar()
end

toDoubleToybox::Lang::Double

Convert a Number to a Double.

Returns:

Since:

  • 1.0.0


6318
6319
# File 'Monkeybrains.rb', line 6318

def toDouble()
end

toFloatToybox::Lang::Float

Convert a Number to a Float.

Returns:

Since:

  • 1.0.0


6306
6307
# File 'Monkeybrains.rb', line 6306

def toFloat()
end

toLongToybox::Lang::Long

Convert a Number to a Long.

Returns:

Since:

  • 1.0.0


6312
6313
# File 'Monkeybrains.rb', line 6312

def toLong()
end

toNumberToybox::Lang::Number

Convert a Number to a Number.

Returns:

Since:

  • 1.0.0


6300
6301
# File 'Monkeybrains.rb', line 6300

def toNumber()
end