Wrong calculation lot's of digits

Hi all,

I got a question. why does dynamo sometime calculate wrong. look at this example


in thw last code block on index [7] the calculated number is wrong.
how can i prevent dynamo in this. because later on in one of my processes i have to use list.containsitem with a different list which has the correct number of -0.08 in it but the answer wil be false due to the wrong number.

hope someone can explain/solve this for me?

this is my file:
Why these digits 0_01.dyn (3.2 KB)

Using simple dynamo studio (Core1.3.4.6666/studio 1.3.0.946)
Gr Edward

Wouldn’t Rounding the Digits Solve the Problem?

1 Like

I haven’t seen just plain wrong values like that before. Maybe it’s the older version your using?

https://dynamobuilds.com/

Edit:
Guess my eye don’t work, I missed the ‘8’ completely in that value and just seen ‘00000’.

1 Like

I don’t think it’s wrong. It has to do with the way that double-precision floating point numbers work. This isn’t unique to Dynamo.

https://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/

So basically, if you need precision out to the 16th decimal place, don’t use a double. Or just round it off :slight_smile:

5 Likes

Hi @1234eddie like @ashwinash112 said maybe try use Round function

cheers

2 Likes

What’s the source of those numbers? Revit measurements?

I don’t think it’s wrong. It has to do with the way that double-precision floating point numbers work. This isn’t unique to Dynamo.
https://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/
So basically, if you need precision out to the 16th decimal place, don’t use a double. Or just round it off :slight_smile:

@zachri.jensen is correct - this isn’t a Dynamo thing, but rather a dot net thing - C# Online Compiler | .NET Fiddle with double precision numbers :slight_smile:

I suggest you round the numbers like others have mentioned in this thread!

6 Likes

Thanks everybody.
i know understand why it’s happening.

for now i solved it for myself by using ‘object to string’ followed by ‘string to number’.

1 Like