LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

negative numbers with 2 digits of percision

Solved!
Go to solution

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:

 

deljenje.PNG

 

 

 

 

 

 

please help. thank you

0 Kudos
Message 1 of 9
(3,303 Views)

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.

LabVIEW 2012 32 bit

I am not an expert!
0 Kudos
Message 2 of 9
(3,296 Views)

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.

 

0 Kudos
Message 3 of 9
(3,293 Views)
Solution
Accepted by topic author gtu

Hi gtu,

 

it's not a problem of two's complement, it's just simple math: the remainder has to be positive, so quotient will be one less then expected (by you) for negative numbers.

 

Solved by simple math:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 9
(3,289 Views)

thank you so much!!! 🙂

0 Kudos
Message 5 of 9
(3,277 Views)

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.

0 Kudos
Message 6 of 9
(3,255 Views)

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.

 

0 Kudos
Message 7 of 9
(3,246 Views)

Hi gtu,

 

you really tried that?

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 9
(3,235 Views)

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?

 

0 Kudos
Message 9 of 9
(3,229 Views)