Breadcrumbs

round() Operation


Syntax


set aFloat = aFloat.round(base)


Semantics

round() rounds float to a given base. E.g. if you want to remove the fraction then base is 1.0. The common method is implemented:

  • Decide which is the last digit to keep.

  • Increase it by 1, if the next digit is 5 or more (this is called rounding up).

  • Leave it the same, if the next digit is 4 or less (this is called rounding down).
    See also Rounding on Wikipedia.

Substitutables

aFloat

Can be any variable or object attribute having the type Float

base

Is of type Float and encodes the base to be rounded to. For examples, see the table below.

Examples


set aFloat1 = aFloat1.round(2); 
set aFloat2 = aFloat3.round(aFloat4);


Table: Base Examples for the round() Operation

Rounding Result

aFloat

Base

3

3.1

1.0

3

3

1.0

3

3.499

1.0

4

3.999

1.0

4

3.5

1.0

4

3.501

1.0

-3

-3.1

1.0

-3

-3

1.0

-3

-3.499

1.0

-4

-3.999

1.0

-4

-3.5

1.0

-4

-3.501

1.0

999999999999999999999999999.499

999999999999999999999999999.499

0.001

3.499

3.499

0.001

3.5

3.499

0.01

3.5

3.499

0.1

3.5

3.499

0.5

3

3.499

1.0

0

3.499

10.0

-3.499

-3.499

0.001

-3.5

-3.499

0.01

-3.5

-3.499

0.1

-3.5

-3.499

0.5

-3

-3.499

1.0

0

-3.499

10.0


Related Pages: