Hey guys!
I recently bumped into a problem when I was calculating with simple additions. I had declared a variable eariler that we'll name "range" here.
In a loop range was added "+1". If a certain value was reached ( another variable ) then range was added with "+0.1" instead. Now this is where the issue occured.
The problem was identified as a "floating point issue" through several hours of google'ing, in other words the value I wanted wasn't for example -45.1 but something close to -45.1 like
-45.1000000004.
So I tried different solutions like type-casting with string. But then the instrument I was communicating with had problems (the range variable was used for input to a instrument). I really needed the double/float variable to be with one decimal (e.g 45.1) and not as a string or a float with bit issues.
So I went after the Decimal class, but I kept getting annoyed by the fact that you couldn't get the value only but you had to receive the whole class signature ( for example Decimal("-45.1" ). Now that is a really bad input for my instrument.
So I was wondering if you guys know a solution?, is it possible to recieve the value only, after calculations with the Decimal module. Or do I have to pull some dirty tricks on this one? :-)
I recently bumped into a problem when I was calculating with simple additions. I had declared a variable eariler that we'll name "range" here.
In a loop range was added "+1". If a certain value was reached ( another variable ) then range was added with "+0.1" instead. Now this is where the issue occured.
The problem was identified as a "floating point issue" through several hours of google'ing, in other words the value I wanted wasn't for example -45.1 but something close to -45.1 like
-45.1000000004.
So I tried different solutions like type-casting with string. But then the instrument I was communicating with had problems (the range variable was used for input to a instrument). I really needed the double/float variable to be with one decimal (e.g 45.1) and not as a string or a float with bit issues.
So I went after the Decimal class, but I kept getting annoyed by the fact that you couldn't get the value only but you had to receive the whole class signature ( for example Decimal("-45.1" ). Now that is a really bad input for my instrument.
So I was wondering if you guys know a solution?, is it possible to recieve the value only, after calculations with the Decimal module. Or do I have to pull some dirty tricks on this one? :-)
Comment