cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

1-Newbie

## Can I change the resolution / accuracy of Isodraw numbers?

I'm trying to write a macro that rounds numbers. The code asks users for a number, and the macro rounds to 2 after the decimal place. First of all, I'd like to know if Isodraw has a built in round function. That would save me some time. I searched the 7.2 IML Reference (even though I'm using 7.3 because I can't seem to get access to 7.3 IML) and there didn't seem to be a built in round function. Nonetheless I proceeded to write a rounding submacro which takes a user input for a number and rounds the 2nd digit after the decimal. However I noticed that my numbers were often altered after I input them. And so I used this text macro to test it:

macro numtest

define number as float

define numasstring as string

number = get float "Number"

numasstring = number

message numasstring

end macro

When I input 8.591, I get 8.59.

Similarly,

8.592 --> 8.592

8.593 --> 8.593

8.594 --> 8.593

8.595 --> 8.595

8.596 --> 8.596

8.597 --> 8.596

8.598 --> 8.598

8.599 --> 8.599

8.600 --> 8.599

It seems like the resolution of Isodraw's numbers are set somewhere. Why does Isodraw do this, and how can I change the resolution / accuracy of the numbers?

1 ACCEPTED SOLUTION

Accepted Solutions
3-Visitor
(To:ttea)

First, not aware of a way to control number of places for a float. Second, it actually appears to be a bug.

I took a slightly modified version of your macro...

Macro test

define number as float

number = 1.555

message number * 2

End Macro

Which comes out to 3.109. If I switch it to 1.5555 as below...

Macro test

define number as float

number = 1.5555

message number * 2

End Macro

I then get 3.111 which is correct.

I guess I've never had to get to that level or the inconsistency was just never caught by our users. You may want to contact support.

Note that I'm on 7.3, M031 build 1.

3 REPLIES 3
3-Visitor
(To:ttea)

First, not aware of a way to control number of places for a float. Second, it actually appears to be a bug.

I took a slightly modified version of your macro...

Macro test

define number as float

number = 1.555

message number * 2

End Macro

Which comes out to 3.109. If I switch it to 1.5555 as below...

Macro test

define number as float

number = 1.5555

message number * 2

End Macro

I then get 3.111 which is correct.

I guess I've never had to get to that level or the inconsistency was just never caught by our users. You may want to contact support.

Note that I'm on 7.3, M031 build 1.

1-Newbie
(To:thendricks)

Thanks for replying, Trevor. I'll try contacting customer support.

For anyone who is interested, I'll also post my rounding code when it's finished. It's been giving me a bit of trouble so far.

1-Newbie
(To:ttea)

Here is a rounding submacro for anyone who is interested.

To run it you can just use:

result = RUN round(number, place)

where number is the number you want to round, and place is the rounding place after the decimal.

E.g.

result = RUN round(8.599,2) will return 8.60

result = RUN round(8.599,1) will return 8.6

result = RUN round(8.599,0) will return 9

It can currently handle 0, 1 and 2 places after the decimal, and can probably be modified to do places before the decimal, but  that went beyond the scope of my purpose.

If anyone can see a way to improve this, let me know!

submacro round(float number, integer place)

# This macro is used for rounding to 0 decimals, 1 decimals or 2 decimals.
# The format goes: round(number, place) where number is the number you want to round and place is 0,1 or 2.
# This is used in conjunction with mm_on_top and inch_on_top to round the converted result.

define numstring as string
define newnumstring as string
define placefactor as integer
define length as integer
define decloc as integer
define rounddigit as integer
define rounder as integer
define rounddigitloc as integer
define OSBRD as integer

define roundednum as string
define roundeddecloc as integer
define newplace as integer

define ninefactor as integer
define decfactor as integer

newnumstring = number
#message newnumstring
numstring = number
decloc = find(numstring,'.',1)
length = len(numstring)
if (decloc = 0) then
newnumstring = numstring + '.'
numstring = newnumstring
end if
decloc = find(numstring,'.',1)
if (length-decloc < 2) then
while ((length-decloc) < 2)
newnumstring = numstring + '0'
numstring = newnumstring
length = len(numstring)
end while
end if
decloc = find(numstring,'.',1)
if (place <= 0) then
placefactor = place-1
else
placefactor = place
end if
rounddigit = mid(numstring,decloc+placefactor,1)      #Change -1 --> +1
ninefactor = 0
rounddigitloc = len(left(numstring,decloc+placefactor-ninefactor))    #Change -1 --> +1
rounder = mid(numstring,rounddigitloc+1,1)
if (rounder = ".") then
rounder = mid(numstring,rounddigitloc+2,1)
# message "decimal reached"
end if
if (rounder < 5) then
roundednum = left(numstring,decloc+placefactor)      #Change -1 --> +1  #DONE
end if
if (rounder >= 5) then
if (rounddigit = 9) then
while (rounddigit = 9)
ninefactor = ninefactor+1
rounddigit = mid(numstring,decloc+placefactor-ninefactor,1)
# tempnumstring = ninefactor
# message "nine factor is now " + tempnumstring
if (rounddigit = ".") then
ninefactor = ninefactor+1
rounddigit = mid(numstring,decloc+placefactor-ninefactor,1)
#  message "decimal reached"
end if
newnumstring = ninefactor
# message "current ninefactor: " + newnumstring
end while
rounddigitloc = len(left(numstring,decloc+placefactor-ninefactor))
OSBRD = decloc-rounddigitloc-1
number = rounddigit
newnumstring = number + 1
number = newnumstring
newnumstring = left(numstring,rounddigitloc-1) + number
roundednum = left(numstring,rounddigitloc-1) + number
if (ninefactor > 0) then
if (OSBRD > 0) then
for number = 1 to OSBRD
newnumstring = roundednum + '0'
roundednum = newnumstring
end for
end if
roundeddecloc = find(roundednum,'.',1)
if (place > 0) then
if (roundeddecloc = 0) then
newnumstring = roundednum + '.'
roundednum = newnumstring
end if
roundeddecloc = find(roundednum,'.',1)
newplace = len(roundednum)-roundeddecloc
while (newplace < place)
newnumstring = roundednum + '0'
roundednum = newnumstring
newplace = len(roundednum)-roundeddecloc
end while
end if
end if
else
rounddigitloc = len(left(numstring,decloc+placefactor-ninefactor))  #Change -1 --> +1
number = rounddigit+1
newnumstring = left(numstring,rounddigitloc-1) + number
roundednum = left(numstring,rounddigitloc-1) + number
end if
end if
return roundednum
end submacro

Announcements
Top Tags