Do decimal fractions count as odd or even numbers?

ulrichburke

New member
Joined
Jun 10, 2016
Messages
8
Dear All.

OK, I've got a FEELING this is a dumbass question before I answer it, I just haven't thought of decimals like this before. I've started learning to code Java, hit a bit of instructions I didn't understand and then this point got me.

If I have 0.246, does that count as an even number because 246 divides by 2?

If I have 0.579, does that count as an ODD number because 579 DOESN'T divide by 2?

The above are just 'for instances', I'm really asking 'if the number after the decimal point is finite - some decimals carry on forever, seems like! - and would divide by 2 if it WASN'T after a decimal point, would it count as an even number for computational purposes? Ditto with odd numbers, if they DON'T divide by 2, if you get me.

It's just in this Java question I'm trying to wrap my head around as part of a program, I've got to check if a number's odd or even. My answer worked fine for integers, not for decimals, and I was wondering if I could use an 'if-then' statement that covered decimals AS THOUGH they were whole numbers, just so I've got one 'if-then' doing everything and not having to nest if-thens to allow for decimals (which is the only way I can think of handling the prob. ATM, I'm a VERY beginner Java programmer!)

Got a feeling decimals don't work like that but don't know for sure because I've never thought about this one before!Dear All.

OK, I've got a FEELING this is a dumbass question before I answer it, I just haven't thought of decimals like this before. I've started learning to code Java, hit a bit of instructions I didn't understand and then this point got me.

If I have 0.246, does that count as an even number because 246 divides by 2?

If I have 0.579, does that count as an ODD number because 579 DOESN'T divide by 2?

The above are just 'for instances', I'm really asking 'if the number after the decimal point is finite - some decimals carry on forever, seems like! - and would divide by 2 if it WASN'T after a decimal point, would it count as an even number for computational purposes? Ditto with odd numbers, if they DON'T divide by 2, if you get me.

It's just in this Java question I'm trying to wrap my head around as part of a program, I've got to check if a number's odd or even. My answer worked fine for integers, not for decimals, and I was wondering if I could use an 'if-then' statement that covered decimals AS THOUGH they were whole numbers, just so I've got one 'if-then' doing everything and not having to nest if-thens to allow for decimals (which is the only way I can think of handling the prob. ATM, I'm a VERY beginner Java programmer!)

Got a feeling decimals don't work like that but don't know for sure because I've never thought about this one before!

Yours hopefully

Chris.
 
Only non-zero integers are classified as odd or even.

If you did define decimals as odd or even, in the way you describe, you would have a problem:

eg 0.579 is odd, 0.5790 is even, but 0.579 = 0.5790. Can't be both!
 
I am going to disagree slightly with Harry, which probably means I am wrong.

The notion of "even" frequently is applied to integers. Harry's exclusion of zero from the even numbers is not a universal usage. For example, see https://en.m.wikipedia.org/wiki/Parity_(mathematics)

Many do not consider wikipedia to be an authoritative source (it is certainly not reliable on certain topics). But usage is a matter of use by definition. And the wiki article at least proves that a fair percentage of numerate people do not exclude zero from the category of even numbers.

Here are definitions that match usage.

\(\displaystyle x \text { is even } \iff \text { both } x \text { and } \dfrac{x}{2} \text { are integers.}\)

\(\displaystyle x \text { is even } \iff \text { both } x \text { and } \dfrac{x}{2} \text { are natural numbers.}\)

With respect to the second definition, whether zero is even depends on your definition of the natural numbers. If zero is excluded from the natural numbers, then zero is not an even number by the second definition of even numbers. If zero is included among the natural numbers, then zero is an even number.

The critical point is that under either definition, there are "numbers" that are not even, that are instead odd. The value of the notion of "even" is that it breaks the class defined as "numbers" into two disjoint, non-empty subsets.

If we take that general type of definition, it makes no sense to extend the notion of "even" to rational (or real) numbers. Any rational number divided by 2 is still a rational number. So there are no "odd" numbers and no creation of disjoint, non-empty subsets.

There is, however, no bar to making up definitions that differ from common ones so long as you disclose that you are not using a standard definition. You could say:

\(\displaystyle x \text { is "even" for my purposes } \iff \text { both } x \text { and } \dfrac{x}{2} \text { are rational numbers}\)

\(\displaystyle \text {that can be expressed exactly in no more than 3 decimal digits.}\)

Whether such a definition is of much use, I do not know, but no one should object to it if it is useful in certain circumstances. If there is anything math can teach everybody, it is that definitions are important.
 
Last edited:
Dear All.

OK, I've got a FEELING this is a dumbass question before I answer it, I just haven't thought of decimals like this before. I've started learning to code Java, hit a bit of instructions I didn't understand and then this point got me.

If I have 0.246, does that count as an even number because 246 divides by 2?

If I have 0.579, does that count as an ODD number because 579 DOESN'T divide by 2?

The above are just 'for instances', I'm really asking 'if the number after the decimal point is finite - some decimals carry on forever, seems like! - and would divide by 2 if it WASN'T after a decimal point, would it count as an even number for computational purposes? Ditto with odd numbers, if they DON'T divide by 2, if you get me.

It's just in this Java question I'm trying to wrap my head around as part of a program, I've got to check if a number's odd or even. My answer worked fine for integers, not for decimals, and I was wondering if I could use an 'if-then' statement that covered decimals AS THOUGH they were whole numbers, just so I've got one 'if-then' doing everything and not having to nest if-thens to allow for decimals (which is the only way I can think of handling the prob. ATM, I'm a VERY beginner Java programmer!)

Got a feeling decimals don't work like that but don't know for sure because I've never thought about this one before!

How about telling us the context of your question? What were the instructions for this program? Or, if checking for odd or even is just part of what you are doing, why are you doing it?

The usual definition of odd and even applies only to integers, so one would just return either "false" or some sort of "N/A".

It is conceivable that you could extend that definition, but you would need a reason for your choice. What is the effect of taking 0.246 as even?
 
Fair enough, JeffM. Never been quite sure myself about 0.

Here is another example. If one defines "a prime number as a positive integer that is divisible by itself and one." Doesn't the make one a prime?

If on the other hand, one defines "a prime number as a positive integer that has exactly two divisors" Then is one prime?
 
Here is another example. If one defines "a prime number as a positive integer that is divisible by itself and one." Doesn't the make one a prime?

If on the other hand, one defines "a prime number as a positive integer that has exactly two divisors" Then is one prime?

Interestingly, there was a time when it was common to call 1 prime. Today that is nonstandard; but it is still easy to state our definitions too loosely, and accidentally imply it is.
 
Thanks for all the wonderful answers, here's the answer to someone's question!

Dear All.

So you're looking at someone who has problems programming a microwave, but who wanted to get the hang of programming languages! I got a version of Basic and a .PDF about Java and one of the challenges in the very beginning of the Java book was to get a list of numbers and split them up into odds and evens, storing the results in two arrays.

Which I did. The input and FOR-NEXT loop worked perfectly - unless I put in a number with a decimal bit. Then the whole little program died a miserable death! So I couldn't think what to do to make it work with decimals. Remembering I've never tried programming before so this is possibly the worst solution you've ever heard of, I did a loop to multiply the number by 10 recursively until the decimal point was at the end, have a variable to hold how many times it had to BE multiplied by 10 to get the decimal point to the end, check to see if the now mile-long but not decimal number divided by 2 an exact number of times. If it DID divide an exact number of times, number was even, move the decimal point BACK to the left the amount of times stored in the spare variable, store the whole thing in the EVEN NUMBERS table. If it DIDN'T, number was odd, move the decimal point back the amount of places held in the spare variable, put the number in the ODDS table.

I'm absolutely certain that's the wrong way to do it but I flat couldn't think of any other way!!

When you've all finished doing tickled hyena impressions, at least you now know why I wanted to know (and why I was a bit embarrassed about saying the above because you're all so much more experienced in the art of programming!!)

Yours from a VERY beginner programmer (that was the thinking behind my first ever program!)

Chris.
 
Dear All.

So you're looking at someone who has problems programming a microwave, but who wanted to get the hang of programming languages! I got a version of Basic and a .PDF about Java and one of the challenges in the very beginning of the Java book was to get a list of numbers and split them up into odds and evens, storing the results in two arrays.

Which I did. The input and FOR-NEXT loop worked perfectly - unless I put in a number with a decimal bit. Then the whole little program died a miserable death! So I couldn't think what to do to make it work with decimals. Remembering I've never tried programming before so this is possibly the worst solution you've ever heard of, I did a loop to multiply the number by 10 recursively until the decimal point was at the end, have a variable to hold how many times it had to BE multiplied by 10 to get the decimal point to the end, check to see if the now mile-long but not decimal number divided by 2 an exact number of times. If it DID divide an exact number of times, number was even, move the decimal point BACK to the left the amount of times stored in the spare variable, store the whole thing in the EVEN NUMBERS table. If it DIDN'T, number was odd, move the decimal point back the amount of places held in the spare variable, put the number in the ODDS table.

I'm absolutely certain that's the wrong way to do it but I flat couldn't think of any other way!!

When you've all finished doing tickled hyena impressions, at least you now know why I wanted to know (and why I was a bit embarrassed about saying the above because you're all so much more experienced in the art of programming!!)

Yours from a VERY beginner programmer (that was the thinking behind my first ever program!)

Chris.


The exercise is using "number" to mean "integer", or very likely even "natural number". So all the stuff with decimals is unnecessary. They probably don't expect you to even consider entering a decimal; but the proper thing to do would be to check for that and just display an error message.
 
Here is another example. If one defines "a prime number as a positive integer that is divisible by itself and one." Doesn't the make one a prime?

If on the other hand, one defines "a prime number as a positive integer that has exactly two divisors" Then is one prime?
I suspect that one reason to define a prime as a positive integer that has only one divisor greater than 1 is that such a definition results in a very simple formulation of the fundamental theorem of arithmetic: every composite number has a unique factorization in primes (except for the ordering of the factors).
 
Dear All.

So you're looking at someone who has problems programming a microwave, but who wanted to get the hang of programming languages! I got a version of Basic and a .PDF about Java and one of the challenges in the very beginning of the Java book was to get a list of numbers and split them up into odds and evens, storing the results in two arrays.

Which I did. The input and FOR-NEXT loop worked perfectly - unless I put in a number with a decimal bit. Then the whole little program died a miserable death! So I couldn't think what to do to make it work with decimals. Remembering I've never tried programming before so this is possibly the worst solution you've ever heard of, I did a loop to multiply the number by 10 recursively until the decimal point was at the end, have a variable to hold how many times it had to BE multiplied by 10 to get the decimal point to the end, check to see if the now mile-long but not decimal number divided by 2 an exact number of times. If it DID divide an exact number of times, number was even, move the decimal point BACK to the left the amount of times stored in the spare variable, store the whole thing in the EVEN NUMBERS table. If it DIDN'T, number was odd, move the decimal point back the amount of places held in the spare variable, put the number in the ODDS table.

I'm absolutely certain that's the wrong way to do it but I flat couldn't think of any other way!!

When you've all finished doing tickled hyena impressions, at least you now know why I wanted to know (and why I was a bit embarrassed about saying the above because you're all so much more experienced in the art of programming!!)

Yours from a VERY beginner programmer (that was the thinking behind my first ever program!)

Chris.
Chris, what you did was quite clever but has the major flaw that Harry_the_cat pointed out. Unlike natural numbers, when you have decimal numbers you can change the ending by adding a 0 at the end, making the number look even.

I remember a little over 100 years ago doing just what you did, but it was to round off a number say to the 1000th place. can you think of how I did that?
 
Top