## What's the difference between Trunc and Int?

Hints, tips and tricks for newbies

Moderators: JRL, Dorian (MJT support)

### What's the difference between Trunc and Int?

For a widely range of values tested by me in Macroscheduler (positive and negative values), Trunc and Int functions returns a same integer value. If possible, I wish a example where Trunc and Int evaluates in a different integer value.

In addition, never occured in my tests a round operation in both functions, only a truncate operation. Is this behavior expected? What's the meaning of the words " ... rounded toward zero." in Macroscheduler's help for this two functions?

Thank you.
Humanetico
Newbie

Posts: 4
Joined: Tue Aug 16, 2011 6:03 am

### Share On:

Does this info help? I suspect there might be a difference between a floating point value and an integer value in Delphi but not in Macro Scheduler. Macro Scheduler is written in Delphi.

JRL
Automation Wizard

Posts: 3160
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

===
The Round function rounds a floating point Number to an Integer value.

The rounding uses Bankers rules, where an exact half value causes a rounding to an even number:

12.4 rounds to 12
12.5 rounds to 12 // Round down to even
12.6 rounds to 13

13.4 rounds to 13
13.5 rounds to 14 // Round up to even
13.6 rounds to 14

===

I made a test and Macroscheduler use Bankers rules too in your Round function, although in Macroscheduler help is said: " ... If X is exactly halfway between two whole numbers, the result is the number with the greatest absolute magnitude.".

Thanks.
Humanetico
Newbie

Posts: 4
Joined: Tue Aug 16, 2011 6:03 am