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.
Syntax
Examples
Integer i = 42;
Float f = 3.14;
Constructors
Float()
Default constructor.
Declaration
Float Float()
Returns
| Type | Description |
|---|---|
| Float |
Examples
Integer i = 42;
Float f = 3.14;
Float(Float)
Pass a value to copy into a new object.
Declaration
Float Float(Float value)
Parameters
| Type | Name | Description |
|---|---|---|
| Float | value | Float object. |
Returns
| Type | Description |
|---|---|
| Float |
Examples
Float m = 3.14;
Float pi = Float(m);
Float e = Float(2.71);
Float(Integer)
Pass an Integer and have it converted to a Float object.
Declaration
Float Float(Integer value)
Parameters
| Type | Name | Description |
|---|---|---|
| Integer | value | Integer object. |
Returns
| Type | Description |
|---|---|
| Float |
Examples
Integer n = 10;
Float discount = Float(n);
Float vat = Float(25);
printLine(discount.toString(1) + ", " + vat.toString(2));
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". |
Returns
| Type | Description |
|---|---|
| Float |
Examples
Integer i = 42;
Float f = 3.14;
Float(String)
Pass a String containing a number. The constructor will parse the text and create a Float object.
Declaration
Float Float(String value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | value | A String containing a number. For example "3.14". |
Returns
| Type | Description |
|---|---|
| Float |
Examples
String o = "1.618";
Float phi = Float(o);
Float twoSquared = Float("1.4142");
Methods
abs()
Converts a float value to its absolute value (the non-negative value of the number without regarding the sign).
Declaration
Float abs()
Returns
| Type | Description |
|---|---|
| Float |
Examples
Float i = -7.14;
print(i.abs().toString(2));
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()
Returns
| Type | Description |
|---|---|
| Integer |
Examples
Float f = 13.456;
print(f.floor().toString())
isNull()
Returns true if it has no value and false if it does.
Declaration
Bool isNull()
Returns
| Type | Description |
|---|---|
| Bool |
Remarks
A NULL/NUL/NIL Float is different from zero, in that it is conceptually without a value. However, when a null Float is used naively, CRMScript is usually forgiving and interprets it as zero.`n
Examples
Integer i = 42;
Float f = 3.14;
round()
Returns the Integer approximation of the Float without any decimals. It is calculated by rounding to the nearest Integer.
Declaration
Integer round()
Returns
| Type | Description |
|---|---|
| Integer |
Examples
Float f = 13.79;
print(f.round().toString());
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)
Parameters
| Type | Name | Description |
|---|---|---|
| Integer | decimals | Number of decimal digits. |
Returns
| Type | Description |
|---|---|
| String |
Remarks
You must always specify how many decimal digits you want.
Examples
Float pi = 3.14159;
for(Integer i = 0; i < 6; i++) {
printLine(pi.toString(i));
}