7.04 Rounding

INT

Function:

Rounds x downwards to the nearest integer. The value is always towards zero even for negative numbers.

Syntax:

INT(x) 

Examples:

put int(2.5)    // 2
put int(-2.5)   // -2

FIX

Function:

Rounds x upwards to the nearest integer. The value is always away from zero even for negative numbers.

Syntax:

FIX(x) 

Examples:

put fix(2.5)    // 3
put fix(-2.5)   // -3

FLOOR

Function:

Returns x rounded downwards to an integer value.

Syntax:

FLOOR(x) 

Examples:

put floor(2.5)  // 2
put floor(-2.5) // -3

CEIL

Function:

Returns x rounded upwards to an integer value.

Syntax:

CEIL(x) 

Examples:

put ceil(2.5)    // 3
put ceil(-2.5)   // -2

FRAC

Function:

Returns fractional part of x.

Syntax:

FRAC(x) 

Examples:

put frac(2.5)    // 0.5
put frac(-2.5)   // -0.5

ROUND

Function:

Returns x rounded to the nearest integer or a real number with 'decs' decimal digits.

Syntax:

ROUND(x[, decs]) 

Examples:

put round(PI, 3)    // 3.142
put round(-PI, 3)   // -3.142
put round(22/7, 3)  // 3.143

lynplex/lp0704.txt · Last modified: 2012/09/08 15:12 (external edit)