Codesnippets > Math

Is Number Entered a whole number or not?

(1/2) > >>

mrplant:
My brains gone to sleep today.
User enters a number at the keyboard. Its  a real number. Say 10.2 or 10.6 or 10.8 or 11.4 - How do I reject any input that isn't a whole exact number?
I am trying to use FMOD but my formula must be dodgy..

Anyone?

erico:
With the INTEGER() command.
Do you need to round it to the closest integer or just get rid of the decimals?

edit: oh wait...do you mean not to accept the number at all if it is not an integer?

mrplant:
I am writing a calculator for doing the change machine at work..

What I am doing is asking the user how many 20p coins they have.
They enter say 6
This makes 0.20 x 6 = 1.20
I want to reject that input and get them to re-enter it. (The machine should always hold an exact not a fractional part of a pound in coins)
valid inputs would be a number of twenty pence coins that come to an exact pound.
A total amount of coins that comes to 1.20 or 1.40 or 1.60 or 1.8 are all invalid.

I know the solution is integer related but my brain has failed me today..

This isn't working properly:

IF INTEGER((TwentyPences*0.20)-INTEGER(TwentyPences*0.20)) <> 0 // If  we have a non exact amount here eg 79.80 instead of 80.00 pounds for example.
   // Print "(STRANGE TOTAL - PLEASE CHECK MACHINE AGAIN"

Well its working perfectly in fact - just not giving the the results I need lol!

erico:
hmm, that example should work I guess?
But I had my share on integer alien outcomes and am not that good in math at all.

Let´s say, don´t calculate inside the integer command brackets. Can you give that exact idea a try but with variables outside?

mrplant:
Silly me - I was over thinking the problem..

Since I took input in 20pences and 5 make a pound, I just had to look at the modulus after dividing by 5 for my answer...

IF MOD(TwentyPences,5) <> 0 // If remainder of dividing by 5 is not zero, we have a non exact amount here eg 79.80 instead of 80.00 pounds for example.

Navigation

[0] Message Index

[#] Next page

Go to full version