Class Float

A class for representing floating point numbers as objects. Floats are approximations of real numbers written with decimals. If you don't need to work with decimals, use the Integer data type.

Examples

Integer i = 42;
Float f = 3.14;

Constructors

Float()

Default constructor.

Declaration

Float Float()

Type Description
Float

Float(Float)

Pass a value to copy into a new object.

Declaration

Float Float(Float value)

Examples

Float m = 3.14;
Float pi = Float(m);
Float e = Float(2.71);

Parameters

Type Name Description
Float value Float object.

Type Description
Float

Float(Integer)

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

Declaration

Float Float(Integer value)

Examples

Integer n = 10;
Float discount = Float(n);
Float vat = Float(25);
printLine(discount.toString(1) + ", " + vat.toString(2));

Parameters

Type Name Description
Integer value Integer object.

Type Description
Float

Float(String)

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

Declaration

Float Float(String value)

Examples

String o = "1.618";
Float phi = Float(o);
Float twoSquared = Float("1.4142");

Parameters

Type Name Description
String value A String containing a number. For example "3.14".

Type Description
Float

Float(Long)

Create a new Float instance from a Long instance.

Declaration

Float Float(Long value)

Parameters

Type Name Description
Long value A Long containing a number. For example "314L".

Type Description
Float

Methods

toString(Integer)

Converts a float value to its string representation.

One of the most frequently used methods, typically when you are going to output something.

Declaration

String toString(Integer decimals)

Examples

Float pi = 3.14159;
for(Integer i = 0; i < 6; i++) {
	printLine(pi.toString(i));
}

Parameters

Type Name Description
Integer decimals Number of decimal digits.

Returns

Type Description
String

abs()

Converts a float value to its absolute value (the non-negative value of the number without regarding the sign).

Declaration

Float abs()

Examples

Float i = -7.14;
print(i.abs().toString(2));

Returns

Type Description
Float

floor()

Returns the Integer preceding the decimal separator. The floor of a Float is calculated by rounding downward to the nearest Integer.

Declaration

Integer floor()

Examples

Float f = 13.456;
print(f.floor().toString())

Returns

Type Description
Integer

round()

Returns the Integer approximation of the Float without any decimals. It is calculated by rounding to the nearest Integer.

Declaration

Integer round()

Examples

Float f = 13.79;
print(f.round().toString());

Returns

Type Description
Integer

isNull()

Returns true if it has no value and false if it does.

Declaration

Bool isNull()

Returns

Type Description
Bool