Rounding functions ( trunc, round )

Help Contents Logo and Mathematics Mathematical functions (guide) Rounding functions ( trunc, round )
Exponential functions (sqrt, exp, logn ) Trigonometric functions ( sin, cos, tan, cotan )

Rounding functions ( trunc, round )

It is offen needed to calculate an integer result, but the computer gives a non-integer one.

In such cases you may consider asking Logo to modify the number in a way defined by you.

The easiest way is just to ask to truncate a number, leaving out its fractional part.

This is accomplished by the function trunc.

The other way is to define exactly how precise number you need. For such cases you may use round.
	print trunc 3.2 ; 3
	print trunc -4.8 ; -4
	print round 319.425 0 ; 319
	print round 319.425 2 ; 319.43
	print round 319.425 -1 ; 320

Exponential functions (sqrt, exp, logn ) Trigonometric functions ( sin, cos, tan, cotan )