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.
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.