beautypg.com

ProSoft Technology ProSoft i-View User Manual

Page 53

background image

ProSoft i-View ♦ Mobile Process Monitoring and Control Application

Data Source Files

Version 2.0.2

User Manual

ProSoft Technology, Inc.

Page 53 of 106

September 29, 2011

Numeric operators and methods.

num operator
num2

Arithmetic, comparison, logical operators produce the expected results.
Available operators are listed on the operators precedence table shown earlier.
The bitwise and complement operators extract the integral part of the operands
before computing the result

Example:

2+2

returns

4

num[n]

Returns bit n from the integral part of num. Bit 0 is the least significant bit. The
result can be only 0 or 1.

Example:

3[0]

returns

1

Example:

3[1]

returns

1

Example:

3[2]

returns

0

num.to_i

Returns the integral part of num.

Example:

3.666.to_i

returns

3

num.to_f

Returns num

num.to_s
num.to_s(fmt)

Returns a string representation of num optionally formatted according to fmt.
For a description of possible format specifiers refer to the format function.

Example:

3.666.to_s("%02d")

results in

"03"

Example:

3.666.to_s("%02f")

results in

"04"

Example:

3.666.to_s

results in

"3.666"

Example:

25.to_s("%02.1f ºC")

results in

"25.0 ºC"

(

Note that specifying a format in to_s is not a standard feature of Ruby)

num.chr

Returns a string containing a single character represented by the character
code num.

Example:

72.chr

would return

"H"

num.abs

Returns the absolute value of num.

Example: (-

3.66).abs

would return

3.66

num.round

Returns num rounded to the nearest integer.

Example:

3.66.round

would return

4