12-05-2012 03:36 AM
i have a set of numbers from aprox -2000 to 2000. if i have for example -1234 i need to write it out like -12.34.
i cant find a way to do this.
this works good for positive numbers:
please help. thank you
Solved! Go to Solution.
12-05-2012 03:47 AM
Why shouldn't this work for negative numbers? The integer quotient should be negative if you feed a negative number.
One method to work around this would be to check if the input is a negative number before dividing by 100. I don't think this is necessary though seeing that the integer quotient is the smaller(!) negative number anyway. By adding the remainder it should give the two digit precision number just fine.
12-05-2012 03:53 AM
if the input value is negative the result is something like 650,12 for example. i know that negative numbers are represented in two's complement so the result is kind of expected.
12-05-2012 03:59 AM
12-05-2012 05:02 AM
thank you so much!!! 🙂
12-05-2012 08:46 AM - edited 12-05-2012 08:51 AM
Erm... Am I missing something? Couldn't you just convert to a double and divide by (double) 100? ... then use %.2f as a format for display?
Rod.
EDIT: If your numbers do range +/- 2000, there's probably enough resolution in a single precision float.
12-05-2012 08:59 AM
i tried to solve it this way but it is not working. yet again is good for positive numbers and it returns numbers around 650 for negative numbers.
12-05-2012 09:13 AM
12-05-2012 09:20 AM - edited 12-05-2012 09:25 AM
Is you input blue wire signed or unsigned? It should be signed (I16 or I32). Getting numbers around 650 (ie 65000 before dividing) looks very much like you have the bit pattern of a small negative number, but it is being treated as an UNsigned value.
Rod
EDIT: I am guessing, but is your input blue wire a U16?