Rounding Error when summing up multiple fields

Rounding Error when summing up multiple fields

mp9XXKQ
Observer Observer
1,258 Views
7 Replies
Message 1 of 8

Rounding Error when summing up multiple fields

mp9XXKQ
Observer
Observer

Hello,

 

I'm summing up multiple areas, but the sum of the fields is off due to a rounding error. 

The single areas are displayed with the precision of 2 decimals, but the field that's summing up all of them is using more, so the output differs to the sum I get if I sum them up "manually". The formula summing up the multiple instances are even displayed the right way.

Is there any way to fix that without changing the number of decimals?

 

Capture.PNG

 

 

best regards

1,259 Views
7 Replies
Replies (7)
Message 2 of 8

ChicagoLooper
Mentor
Mentor

Hello @mp9XXKQ 

You can try this.....

 

1. UNITS on command line=>Make precision 2 decimal places=>OK

101.JPG

 

2. In the field window->Make precision=Current 

102.JPG

 

Go back to UNITS and change the precision to test the results. On command line you'll need to regen all (REA) for the field to update.

 

 

 

Chicagolooper

EESignature

Message 3 of 8

Kent1Cooper
Consultant
Consultant

@mp9XXKQ wrote:

.... Is there any way to fix that without changing the number of decimals? ....


I doubt it.  The error is not in the rounding -- the rounding is presumably being done correctly -- but in the use of rounded values to add up to something rounded to more decimal places.

 

This will inevitably happen if all or most of the true values are such that they are being rounded up, especially if they're not very far above the rounding breaking point so they're rounding up comparatively far.  If the first three in your example are true values of 3.817, 3.706, 1.8755, then all those differences between true and rounded values will be adding extra to the sum of rounded values.  Just those three crank it up by a total of 0.0115, which more than kicks the total up a notch at 2-decimal-place rounding.

 

The same effect will happen in the opposite direction if too many of the true values are being rounded down.  Sometimes the ups and downs will balance out, but obviously you can't count on that.

Kent Cooper, AIA
0 Likes
Message 4 of 8

cadffm
Consultant
Consultant

Hi,

 

yes, Autocad don't calculate with the displaying values, it uses the real values..

 

>>"Is there any way to fix that without changing the number of decimals?"

Try this:

multiply the individual values by 100,

TRUNC this result

and use the conversion factor of [additional format] to multiply the result by 0.01 back to your needs.

 

If I am not wrong, that should do the job!?

truncX100.JPG

Sebastian

Message 5 of 8

leeminardi
Mentor
Mentor

The sum of full precision numbers that are rounded to a fixed precision will probably be different than the sum of rounded numbers to the same precision.  For example:

leeminardi_0-1662642362943.png

You should add the round function to your field expression.

 

The AutoCAD field round function is different than the Excel round function.  AutoCAD's round function rounds to the closest integer.

  • round(real) = Rounded to the nearest integer

The expression for rounding to 2 decimal places would look something like the following where "number" is the field reference to the value.

round(100.0*number)/100.0

 

lee.minardi
0 Likes
Message 6 of 8

leeminardi
Mentor
Mentor

I didn't see @cadffm 's post when I made my post.  TRUC or ROUND can achieve the same results.

 

Here's an example with ROUND.

leeminardi_0-1662648751993.png

 

lee.minardi
0 Likes
Message 7 of 8

vladimir_michl
Advisor
Advisor

You are probably summing up already rounded values. Make sure that the individual fields you are summing are NOT rounded (format: none or large precision).

 

Vladimir Michl, www.arkance-systems.cz - www.cadforum.cz

 

0 Likes
Message 8 of 8

leeminardi
Mentor
Mentor

Whether to sum rounded numbers or round the sum of higher precision numbers depends on the real world use of the AutoCAD drawing. The fabrication method of an object will determine the appropriate dimensional precision for that object. For example, the precision of locating and then drilling mounting holes near the ends of a bar determines the tolerance for the individual bar. An assembly of multiple bars end-to-end or as a truss or frame should consider the possible variation in the individual bar lengths which could be different than using the nominal length of each bar and then applying a tolerance.

lee.minardi
0 Likes