trunc
Kay C Lan
lan.kc.macmail at gmail.com
Tue Feb 12 04:01:15 CST 2008
On Feb 11, 2008 7:11 PM, Eric Chatonet <eric.chatonet at sosmartsoftware.com>
wrote:
>
> function logicalTrunc n
> if n is not a number then return "NAN"
> return n - (n mod 1)
> end logicalTrunc
>
I don't fully understand Richard's explanation of why machines fail to
represent numbers but I extrapolated that to mean that if trunc doesn't work
then mod would suffer the same failure:
I therefore rewrote Thomas function to include your n - (n mod 1)
alternative, it looks like this:
put 8.3 into Zahl
put Zahl - (Zahl - (Zahl mod 1)) into Dezimal
put Dezimal*60 & comma & (Dezimal*60 - ((Dezimal *60) mod 1))
Placing the above in the Msg Box and using Thomas' same three examples of
8.1, 8.2 and 8.3, the answers are exactly the same as for trunc, 6,5 12,11
& 18,18.
So I think if Thomas wants to get the answer he's expecting he should avoid
both trunc and mod.
HTH
More information about the use-livecode
mailing list