Source language: Translate to:

trunc() function problem

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

trunc() function problem

Postby Aaron » Tue Sep 05, 2006 3:22 pm

When I execute this code:

Code: Select all
Math "trunc(951984987716899/16)" "0" "[Result]"



[Result] is Error instead of 59499061732306.
Aaron
 
Posts: 13
Joined: Fri Apr 01, 2005 7:16 am
Location: Spain

Postby beno » Tue Sep 05, 2006 4:06 pm

Hi Aaron,

I think you can not use the trunc() function inside the Math action.

Why don´t you try:

Code: Select all
Math "951984987716899/16" "0" "[Result]"


I´m sure this will do what you are looking for.

In fact, using Math and 0 decimal places is the same as trunc().

HTH,

beno
User avatar
beno
 
Posts: 678
Joined: Fri Apr 01, 2005 9:03 am
Location: México

Postby Gaev » Tue Sep 05, 2006 4:36 pm

Beno:

According to the Help file ...
decimal places
The number of decimal places to include in the result. Use 0 (zero) to round the result to the nearest whole number
... which is not the same as trunc ... which just truncates (chops off) everything after the decimal point.

Aaron:

Looks like trunc() can not handle anything larger than "1,000,000,000".

But you can get around it using this code ...
Code: Select all
SetVar "[HugeNumber]" "951984987716899"
Math "[HugeNumber]/16" "3" "[HugeAnswer]"
StrParse "[HugeAnswer]" "." "[HugePartA]" "[Junk]"
StrParse "[HugePartA1]" "," "[HugePartB]" "[Junk]"
AlertBox "truncated value is ..." "[HugePartB1]"
Return
... this should take care of regional differences where integer/decimal separators are either "." or ","
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Aaron » Tue Sep 05, 2006 5:09 pm

Thanks Gaev, works fine :)
Aaron
 
Posts: 13
Joined: Fri Apr 01, 2005 7:16 am
Location: Spain

Postby beno » Tue Sep 05, 2006 5:56 pm

Hi Gaev,

You are right. ... as usual... :)

saludos,

beno
User avatar
beno
 
Posts: 678
Joined: Fri Apr 01, 2005 9:03 am
Location: México

Postby HPW » Wed Sep 06, 2006 9:28 am

Using newLISP with 64bit support and integer math:
Code: Select all
hpwNewLispCall "(/ 951984987716899 16)" "[Retvar]"

RetVar would display 59499061732306
Hans-Peter
User avatar
HPW
 
Posts: 2510
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest