Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determine a value is INTEGER
#3
Yeah, these things can be real pains...

Code: (Select All)
Do
    Input "Input a number: "; value!
    If InStr(Str$(value!), ".") = 0 Or InStr(Str$(value!), ".") And Val(Mid$(Str$(value!), InStr(Str$(value!), ".") + 1)) = 0 Then Print "The number is an integer." Else Print "The number is not an integer."
Loop

Looks like it would work, right? Wrong.

10.01 - is not an integer. Okay...
10.001- is not an integer. Okay... 
10.0001 - is not an integer. Okay... 
10.00001 - is not an integer. Okay... 
10.000001 - is an integer. OOPS!!!!!!!!

Taking it to the limits reveals the floating point problems we get in base2 math.

Edit: For fun, it does work if we make it a sting in the first place...

Code: (Select All)
Do
Input "Input a number: "; a$
If InStr(a$, ".") = 0 Or InStr(a$, ".") And Val(Mid$(a$, InStr(a$, ".") + 1)) = 0 Then Print "The number is an integer." Else Print "The number is not an integer."
Loop

Pete
Reply


Messages In This Thread
Determine a value is INTEGER - by TerryRitchie - 07-25-2024, 07:40 PM
RE: Determine a value is INTEGER - by DSMan195276 - 07-26-2024, 12:17 AM
RE: Determine a value is INTEGER - by Pete - 07-26-2024, 12:23 AM
RE: Determine a value is INTEGER - by DSMan195276 - 07-26-2024, 02:33 AM
RE: Determine a value is INTEGER - by Pete - 07-26-2024, 02:41 AM
RE: Determine a value is INTEGER - by Jack - 07-26-2024, 12:25 PM
RE: Determine a value is INTEGER - by Petr - 07-26-2024, 03:02 PM
RE: Determine a value is INTEGER - by Jack - 07-26-2024, 05:25 PM
RE: Determine a value is INTEGER - by DSMan195276 - 07-26-2024, 07:02 PM
RE: Determine a value is INTEGER - by Jack - 07-26-2024, 08:14 PM
RE: Determine a value is INTEGER - by Kernelpanic - 07-26-2024, 10:57 PM
RE: Determine a value is INTEGER - by DSMan195276 - 07-27-2024, 04:30 AM
RE: Determine a value is INTEGER - by Kernelpanic - 07-27-2024, 05:03 PM
RE: Determine a value is INTEGER - by SMcNeill - 07-27-2024, 01:49 PM
RE: Determine a value is INTEGER - by bplus - 07-27-2024, 02:43 PM



Users browsing this thread: 3 Guest(s)