Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String comparison oddity...[SOLVED]
#1
Can anyone explain the logic here?

Code: (Select All)
a$ = "11.2": b$ = "11.1": PRINT a$ > b$, 11.2 > 11.1 ' Both True - Okay
a$ = "-11.2": b$ = "11.1": PRINT a$ > b$, -11.2 > 11.1 ' Both False - Okay
a$ = "11.2": b$ = "-11.1": PRINT a$ > b$, 11.2 > -11.1 ' Both True - Okay
a$ = "-11.2": b$ = "-11.1": PRINT a$ > b$, -11.2 > -11.1 ' [True (Error)] / False NOT Okay

So testing out number comparison using STRING$() instead of the very limited VAL() function. What i discovered is string$() comparison does a great job, even on very large numbers, decimals included, until you get to comparing two negative string numbers. Note in the last comparison the string evaluation is true and should be false for [-11.2 > -11.1] as it is in the numeric variable comparison.

Pete
Reply


Messages In This Thread
String comparison oddity...[SOLVED] - by Pete - 08-05-2022, 06:00 PM
RE: String comparison oddity... - by bplus - 08-05-2022, 06:19 PM
RE: String comparison oddity...[SOLVED] - by Pete - 08-05-2022, 06:34 PM
RE: String comparison oddity... - by SMcNeill - 08-05-2022, 06:21 PM
RE: String comparison oddity... - by SMcNeill - 08-05-2022, 06:27 PM
RE: String comparison oddity...[SOLVED] - by Pete - 08-05-2022, 07:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Determining if variable or static string is passed to a Sub dano 9 1,228 06-20-2025, 06:31 PM
Last Post: CookieOscar
  Most efficient way to build a big variable length string? mdijkens 9 1,900 01-17-2025, 11:36 PM
Last Post: ahenry3068
  REDIM, TYPE, and STRING Woes TerryRitchie 16 3,166 04-13-2023, 05:17 AM
Last Post: DSMan195276
  This program causes QB64 to crash - SOLVED Petr 3 833 03-26-2023, 03:59 PM
Last Post: bplus
Question <solved> QB64 without its IDE GUI ? Fifi 28 6,212 01-14-2023, 06:33 PM
Last Post: mnrvovrfc

Forum Jump:


Users browsing this thread: 1 Guest(s)