Skip to main content
Floats are approximations of real numbers written with decimals. If you don’t need to work with decimals, use the Integer data type.
You can create arrays of any data type to store more than one value at the same time like this: String[] s1;. For a given array, all items must be of the same type. Read more about looping and accessing array items in the fundamentals section.

Constructors

Float Float(Float value)

Pass a Float to copy into a new object.

Float Float(Integer value)

Pass an Integer and have it converted to a Float object.

Float Float(Long value)

Pass a Long and have it converted to a Float object.

Float Float(String number)

Pass a String containing a decimal number. The constructor will parse the text and create a Float object.

Numeric strings

Strings can have numeric content but are always written in quotes.

String toString(Integer decimals)

toString() is one of the most frequently used methods, typically when you are going to output something. It returns a string representation of a Float.
You must always specify how many decimal digits you want.

Math operators

Math functions

Float abs()

abs() will return the absolute value of a Float. That is, the non-negative value of the number without regarding the sign.
This example will print 7.14, without the sign.

Integer floor()

floor() will return the Integer preceding the decimal separator. The floor of a Float is calculated by rounding downward to the nearest Integer.
This example will print 13.

Integer round()

round() will return the Integer approximation of the Float without any decimals. It is calculated by rounding to the nearest Integer.
  • if the 1st decimal is 5, 6, 7, 8, or 9 - round up
  • if the 1st decimal is 0, 1, 2, 3, 4 - round down
This example will print 14.

Zero vs. no value

Before a Float is initialized, it has no value. This is commonly written as NULL, NUL, or NIL.

Bool isNull()

isNull() will return true if it has no value and false if it does.