10-30-2011 12:56 AM
i made a VI that tests for even and odd integers using the quotient/remainder function and the Select function but when i test a decimal it does not work properly.
i have my VI testing to see if the input diveded by 2 gives you a remainder equal to 0, and if it does then it is even and the VI displays a messege saying "Even", but when i put in a decimal ( for example 7.2) the remainder is spitting out 1.2 which is not equal to 0 making my VI not work properly, if anybody can help me with this i would greatly appreciate it and if you could attached a photo that would help me understand what my mistake is, Thanks i have attached my VI for you to look at
10-30-2011 02:08 AM
Decimal number cannot be odd or even. A number has to be an interger in order to be even or odd.
http://www.mathsisfun.com/definitions/even-number.html
10-30-2011 03:15 AM
As has been already said, odd/even is only defined for integers, so you need to tell us what you expect for e.g. 7.2.
While you are at it, you might also think a bit more about your program design:
10-30-2011 09:36 AM
yes having it test to see if the last decimal is even or odd will work but im not sure how i would go about doing that ?
10-30-2011 09:40 AM
Again, the "last decimal" has no meaning unless you decide on a given decimal resolution. If your number is accurate to exactly one decimal digit, you could multiply it by 10, round to the nearest integer, then check for even/odd. See how far you get.
10-30-2011 11:00 AM
Check the vi that I have attached. It will tell you whether the last digit in a number (integer or decimal) is even or odd. You don't need to worry about the length of the decimal fraction. It utilizes strings to separate the fractional part and then finds the last non-zero digit in the fractional part. It will work up to 15 digits after the decimal but as you know, with floating point (doubles), as the significand value increases, the precision of the fractional part decreases.
Hope this helps!
Cheers
Mani
Kudos are the best way to say'thank you'!