Rounding to decimal in fields

Rounding to decimal in fields

yael.vsh
Enthusiast Enthusiast
15,458 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,459 Views
44 Replies
Replies (44)
Message 2 of 45

_Tharwat
Advisor
Advisor

Hope this snapshot helps you to understand the settings. 

 

_Tharwat_0-1602420742824.png

 

0 Likes
Message 3 of 45

hak_vz
Advisor
Advisor

Untitled.png

 

Youtube demonstration for Round down function 

 

https://apps.autodesk.com/ACD/en/Detail/Index?id=2045112649967645682&appLang=en&os=Win64 

 

P.S. I have no relations to this product

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 45

yael.vsh
Enthusiast
Enthusiast

Thanks a lot.

I'm familiar with what you've sent. 

It doesnt solve my problem though, because i have a formula with area as "insert field". I need the field inserted to retain precision settings I've set, and it doesn't. 

0 Likes
Message 5 of 45

yael.vsh
Enthusiast
Enthusiast

Thank you!

I'm hoping for a solution that would work on any computer..

0 Likes
Message 6 of 45

_Tharwat
Advisor
Advisor

If you post your field codes then that should help to check them out closely.

0 Likes
Message 7 of 45

yael.vsh
Enthusiast
Enthusiast

Hi, thank you for your reply.

So here are some snapshots of the fields I'm trying to implement. I will be attaching a DWG with polylines as well in next comment.

 

0 Likes
Message 8 of 45

_Tharwat
Advisor
Advisor

Apparently you did not set the precision to 0.00 as shown into your images yet. !

0 Likes
Message 9 of 45

yael.vsh
Enthusiast
Enthusiast

Here are additional files.

precision of area field doesn't matter.png

0 Likes
Message 10 of 45

yael.vsh
Enthusiast
Enthusiast

I think I forgot to mention that I discovered the problem when I had same exact polyline copied/mirror and same field formula showed once 132.80 and once 132.81

0 Likes
Message 11 of 45

yael.vsh
Enthusiast
Enthusiast

-

0 Likes
Message 12 of 45

yael.vsh
Enthusiast
Enthusiast

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

 

This is the field formula string I've been using.

As you can see, different result for same copied polylines, with same area in properties with LUPREC 8

 

0 Likes
Message 13 of 45

yael.vsh
Enthusiast
Enthusiast

Again, the solution I've thought of was to round it after 4th decimal, but it doesn't let me multiply by 10000

 

I can only round after 4th decimal, because if I do that before, then number like 132099.9996, will show in field as 132.10 and I cannot have that because it doesn't match the properties.

As you understand, I must truncate after 5th digit in the value, otherwise it doesn't achieve my purpose.

 

trunc(round(1328100.00000000*10000)*0.000001)

Message 14 of 45

_Tharwat
Advisor
Advisor

is not this what you are after?

All the required settings for the Filed are available in the same dialog but you need to investigate them.

_Tharwat_0-1602507787649.png

 

0 Likes
Message 15 of 45

yael.vsh
Enthusiast
Enthusiast

No, I need the number to be in meters, with two decimals, with digits matching properties. Which is 132.81

Message 16 of 45

_Tharwat
Advisor
Advisor
0 Likes
Message 17 of 45

yael.vsh
Enthusiast
Enthusiast

The problem is for the solution to work for all kinds of polylines.

Which means that 

123456.8765 in properties shows as 123.45 in field (rounded down)

123454.8765 in properties shows 123.45 (regular)

123499.9998 in properties shows 123.49 (rounded down)

Sounds like simply truncating after 5th digit works, BUT

1328100 in properties shows 132.81 (regular) - and it DIDNT show, showed 132.80, and this is where i discovered that really internal value is 1328099.99999876 and creates a problem for me.

 

I really hope the problem is clear.

 

I really thank you for your time trying to get the problem.

0 Likes
Message 18 of 45

yael.vsh
Enthusiast
Enthusiast

In this example you're not truncating, so won't work for other polylines, where I do need that.

0 Likes
Message 19 of 45

_Tharwat
Advisor
Advisor

So you can use either of the two options based on the polyline's area.

0 Likes
Message 20 of 45

yael.vsh
Enthusiast
Enthusiast

I was thinking of creating an "if" statement in LISP based on the 4th and 5th decimal in area value.

Problem is that if the polyline changes (and it happens, as it is an area of an apartment which undergoes changes), then the field wouldn't know to switch from one category to another, as far as I understand.

 

Different solution I thought of was to include an "if" statement in the field formula itself or to transform the value into string, cut off last four decimals (5th to 8th) and then convert back.

I'm not sure if it's possible to have it done inside the field formula. Wasn't successful when searching on internet for this info.

0 Likes