Page 1 of 1
Cut of Decimals
Posted: Thu Jun 16, 2016 12:47 pm
by joran
Hi good friends of this excellent forum
Can someone please assists me with a simple way to cut of decimals, completely.
I'v have a output, lets say: 4,6678688 . . .or 4,335677 // the digit I will work with is 4, not the result of rounded up or down.
just the whole number, in this case 4.
// thanks in advance // Joran
Re: Cut of Decimals
Posted: Thu Jun 16, 2016 1:02 pm
by Klaus
Hi Joran,
you can use the TRUNC() function!
But since this only works with ENGLISH floating point numbers you will need to do something like this:
...
replace "," with "." in the_floating_point_number
put trunc(the_floating_point_number) into the_leading_decimal
...
Best
Klaus
Re: Cut of Decimals
Posted: Thu Jun 16, 2016 1:57 pm
by dunbarx
Hi.
What Klaus said.
Know that LC often has many means to do the same task, so if you are from Mars, as opposed to the US, you can always:
Code: Select all
put item 1 of yourCrazyForeignNotationalNumber
Here we have one line of code to circumvent a notational issue, by going completely away from notational issues. Klaus did it in two lines, but stayed fully within notational bounds.
Just saying...
Craig Newman
Re: Cut of Decimals
Posted: Thu Jun 16, 2016 2:59 pm
by joran
I tried this and it worked
Code: Select all
command setTruncNumber
local tTrunc, tTruncNumber
put 60 / 13 into tTrunc
// this gives 4.615385
put trunc(tTrunc) into tTruncNumber
answer tTruncNumber
// this gives 4 ! / just what I wanted
end setTruncNumber
But this didn't work
Code: Select all
put put 60 / 13 into tTrunc
put item 1 of Trunc into // ex. varX
answer varX
What am I doing wrong in the second method // Craigs I think
Re: Cut of Decimals
Posted: Thu Jun 16, 2016 3:14 pm
by Klaus
The default itemdelimiter is COMMA, so it does not work for -> 4.123456
but will work for -> 4,123456
Re: Cut of Decimals
Posted: Thu Jun 16, 2016 3:18 pm
by joran
Ok, I understand
thank you so much for answering me, now I know a little more
// Joran
Re: Cut of Decimals
Posted: Thu Jun 16, 2016 4:10 pm
by dunbarx
Hi.
Some work, or at least some consideration, needs to be done when dealing with the interplay of commas and periods, either in number formats or notational separators. This rears its head most commonly with date formats, where the US does it differently than Europe. Really the same issue; identical information is displayed in a different format. The delimiters cannot just be assumed to be uniform without thinking about the context the data is in.
Craig
Re: Cut of Decimals
Posted: Sat Jun 18, 2016 1:28 am
by hpsh
can set itemdel to "."
Code: Select all
command metode3
local tTrunc,tTruncnumber
put 60/13 into tTrunc
set itemdel to "."
put item 1 of tTrunc into tTruncnumber
answer tTruncnumber
end metode3
can also use the mod function
Code: Select all
command modulusNumber
local mNum,myMod
put 60 / 13 into mNum
// this gives 4.615385
put mNum mod 1 into myMod
-- will put 0.615385 into myMod
put mNum - myMod into mNum
answer mNum
// this gives 4 ! / just what I wanted
end modulusNumber
wonder how many ways it is to do this stuff

Re: Cut of Decimals
Posted: Sun Jun 19, 2016 1:53 pm
by Randy Hengst
How about this:
on mouseUp
local mNum
put 60 / 13 into mNum
set the numberFormat to "#."
put the trunc of mNum into mNum
end mouseUp