Re: numberformat, trunc and round

2021-02-02 Thread Curry Kenworthy via use-livecode



jbv:

> if myvar = trunc(myvar) then

Different approach: I prefer "mod" for loop breakouts/pitstops.
Very clean way to determine action for certain loop iterations!
Useful for fractional values too, in LC versions thus far.

> set numberformat to "#.000"

You can easily set the numberformat twice, if necessary, in the loop.
And/or take control over whether your comparison is text or binary.
(The numberformat gets involved when converting binary to text.)

Best wishes,

Curry Kenworthy

Custom Software Development
"Better Methods, Better Results"
LiveCode Training and Consulting
http://livecodeconsulting.com/

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


numberformat, trunc and round

2021-02-02 Thread jbv via use-livecode

Hi list,

This might sound like a dumb question, but I'm scratching my head trying
to find a workaround.
I have this portion of script :
  set numberformat to "#.000"
  if myvar = trunc(myvar) then
get myarray[myvar]
  end if

The problem seems to be that when numberformat is set, both trunc() and 
round()
keep the fractional part of myvar (2.00); and since the indexes of 
myarray

are integers (1,2,3,etc), "get myarray[myvar]" always returns empty...
And I need to set numberformat to "#.000", because there are some 
rather
complex computations processed with the values in myarray inside a main 
loop.
And for various other reasons I can't use indexes with fractional part 
in the

array.
Of course, I could use :
  set numberformat to "#.000"
  set itemdelimiter to "."
  if myvar = trunc(myvar) then
get myarray[item 1 of myvar]
  end if
But that's not very elegant and slows down the script a bit...
Any help would be much appreciated.

Best,
jbv

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode