Rounding error negative numbers in global variable

Is there any way to correctly round a negative number to one decimal?

-0,615 rounded down to one decimal should be -0,6, but evaluates to -0,5 in SolidWorks.

SolidworksParts And Features
Answers 8
EK
EK 2016-02-25 Best Answer

look in Tools > Options > Document Properties > Units

There is settings on how SW manage rounding.

That might be the reason. Check your settings

PV
PV 2016-02-25

Christian,

The only way I can think of is by checking if it's negative or positive and when it is indeed negative to add a 0.05 to the number to be rounded.

That way -0.61 becomes -0.66 and will result in -0.6 instead of -0.5

and -0.65 will become -0.7 instead of -0.6

PV
PV 2016-02-25

Oh dear, it's even worse.

Try this :

Have a positive number 0.64 and round it to the 2 decimal places

I get as result 0.64, which is to be expected.

However when I do the same with -0.64 I get -0.63 even if I do -0.640000 I still get -0.63

Can anyone confirm this?

comment imagecomment image
CB
CB 2016-02-25

I get the same result:

comment imagecomment image
PV
PV 2016-02-25

I'm asking my VAR about it because the Tools > Options > Document Properties > Units

that Elmar mentioned don't seem to have an influence and either we're overlooking something or else this is a bug.

By the way, it seems that any number that you round of to the amount of decimal places that the number has will automatically revert to it be smaller. In other words  round ( -0.6 , 1) = -0.5  and ( -0.666 , 3) = -0.665

PV
PV 2016-02-26

Christian,

My VAR notified me that It is a known issue

SPR 864186

I only can advise you to notify your VAR so that you'll get notified about it

Have a nice one

Peter

EK
EK 2016-02-26

Hi try this,

using round formula and if statement....

CB
CB 2016-02-26

Hi it didn't work to copy/paste the formula, but I got it to work after i modified it:

"a" = - .615

"b" = if ( "a" < 0 , round ( "a" * - 1 , 1 ) * - 1 , round ( "a" , 1 ) )

It works, but it's an unnecessary workaround.

Thanks for the help.

comment imagecomment image