VS:Trunc

From Vectorworks Developer
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Truncates the decimal portion of the specified REAL number, returning the result as a LONGINT value.

Note that direct assignment of a REAL to a LONGINT will result in rounding the REAL to the nearest LONGINT, whereas Trunc always rounds down (if the number is positive).

FUNCTION Trunc(
v :REAL) : LONGINT;
def vs.Trunc(v):
    return LONGINT

Parameters

v REAL Real value to truncate.

Remarks

_c_, 2015.05.23: Pay attention when using Trunc with very large numbers exceeding the Longint limit: 2147483647].

num :=  1000000000000.23456789; { a very large number }
AlrtDialog(Concat(num)); { --> 1000000000000.23 loss of digits }
AlrtDialog(Concat('prec 2: ', Num2Str(2, num) )); { --> 1000000000000.23  OK }
AlrtDialog(Concat('prec -1: ', Num2Str(-1, num) )); { --> 1,0000000000e+12  OK }
AlrtDialog(Concat('prec -2: ', Num2Str(-2, num) )); { --> 1,00000000000235e+12  OK }
AlrtDialog(Concat('prec -3: ', Num2Str(-3, num) )); { --> empty! }
AlrtDialog(Concat('prec -4: ', Num2Str(-4, num) )); { --> empty! }

AlrtDialog(Concat('Trunc: ', Trunc(num) )); { --> 2147483647 fully wrong }
));
 

Example

VectorScript

Trunc(235.04); { returns 235 }
Trunc(235.94); { returns 235 }
Trunc(0.94); { returns 0 }

Python


Version

Availability: from All Versions