Rounding to decimal in fields

Rounding to decimal in fields

yael.vsh
Enthusiast Enthusiast
15,425 Views
44 Replies
Message 1 of 45

Rounding to decimal in fields

yael.vsh
Enthusiast
Enthusiast

Hi. 
So I have a crazy situation.

I'm trying to create a field with area value of a polyline in meters with two decimals, rounded down.

The value should match the one written in properties with LUPREC=4, as an external inspector checks the field to match properties (cutting off the unnecessary digits, hence round down).

I've used TRUNC function and everything was great. 

For example 11577880.1183 in properties shows in field 115.77 m

Until I stumbled onto polyline that shows 1328100 in properties but field shows 132.80. I saw that internal value of area was 1328099.99998. The properties window rounds it, but TRUNC function just cuts off after 5th digit.

I tried rounding the number and thus cutting off all decimals, before truncating it at, but then problem with values like 123199.8563, which in field shows 123.20.

 

The SOLUTION that I thought of would be to round the number after 4th decimal but I can't get it to work in FIELDS. 

Neither multiplying by 10000 works, nor setting the decimal at which to round.

 

Another idea is somehow to use the area field inside formula with precision of 0.0000, which i can't achieve either. Formula fields seem to use the internal value, disregarding set precisions.

 

Anyone can think of a solution or help me achieve mine?

The solution must be within the field expression, as I need the values to update with Polyline.

Thank you!!

 

0 Likes
Accepted solutions (2)
15,426 Views
44 Replies
Replies (44)
Message 41 of 45

yael.vsh
Enthusiast
Enthusiast

I’m really not so knowledgeable in lisp, just had an experience of changing minimally a few codes to suit my needs. 
It sounds interesting what you’re saying, but I have no idea how to code that 🙂 

thanks!

0 Likes
Message 42 of 45

yael.vsh
Enthusiast
Enthusiast

My knowledge of autocad is limited to housing architecture area, so I never worked with such large numbers. Thank you for explaining why trunc or round didn't work on big integer.

0 Likes
Message 43 of 45

ВeekeeCZ
Consultant
Consultant

Just to clarify. AutoCAD works with both reals and integers. You reached the limit of integers. Not reals. The theoretical precision of reals is about 2^-16 (would not recommend relying on numbers beyond 2^-10)

 

I would expect that the issue is just about the TRUCN which converts reals into integers. Not ROUND, not multiplying in general.

0 Likes
Message 44 of 45

yael.vsh
Enthusiast
Enthusiast

Actually, I needed it with “round”, not “trunc”. Didn’t work.

0 Likes
Message 45 of 45

yael.vsh
Enthusiast
Enthusiast
Accepted solution

Yay! It worked! Thank you, thank you!

 

Look at this beauty:

 

(strcat
"%<\\AcExpr (trunc(0.01*(trunc(%<\\AcObjProp Object(%<\\_ObjId "
entObjectID
">%).Area \\f \">%) + 0.0001*(round(10000*(%<\\AcObjProp Object(%<\\_ObjId "
entObjectID
">%).Area \\f \">%)-(trunc(%<\\AcObjProp Object(%<\\_ObjId "
entObjectID
">%).Area \\f \">%))))))) \\f \"%lu2%pr2%ct8[0.01]\">%")
)

 

I really appreciate everyone's replies and patience in trying to understand the problem!

 

0 Likes