VS:Trunc

From Vectorworks Developer
Revision as of 10:31, 24 May 2015 by CBM-c- (talk | contribs) (add remark on failure of Trunc on very large numbers)
Jump to navigation Jump to search

.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

(Orso, 2015.05.23): Pay attention when using Trunc with very large numbers:

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