Here is a brief bit of background information:
Whilst designing a Rule Engine to compare various aspects of a form to desired Inputs i stumbled across the problem of having to check if a number was larger than another number, easy enough with the > and < operators right? Wrong, the type of these two that i have to compare are strings, they have to be strings, its not something that can change.
So wishing to see where the Engine would fail so i would know where to begin i told it to compare "100" to "10,000", you can imagine my surprise when it properly calculated that 10k was larger, then i realised DUH its just comparing string lengths, so i compared 1001 to 1000, again it got it correct, 1001 is larger.
But i was adamant that this should NOT work, so i kept hitting the engine with all sorts of scenarios determined to watch it fail. After a colleague pointed out that the system was capable of comparing 1001 and 1000 as file names and properly ordering, the newest thought was that it compared aschii character values of some sort, testing continued. This WOULD fail, i couldn't accept that it was capable of properly calculating which was greater numerically when both were strings.
So my next thought was that it was lining up the first character of each and comparing values through each part of the string. I finally succeeded when i tested 11,111 to 9,999 and it deemed that 9,999 was greater. Perfect, i was near enough happy that it compared 1 to 9, and 9 won on each time, simple fix, prefix the shorter string with 0's.
Ran this new theory through the engine and once again it was happily calculating which was larger.
However I'm still not convinced, there must be other pitfalls to this type of comparison, but im running short of comparisons to test to prove my theory. So my question to you over-flowers is what scenarios do you think this could fail on?
Have you yourselves tried this before? comparing numbers when they are strings and what were the pitfalls you faced? have i covered them all or am i overlooking some major pitfalls?
I'm not convinced this method is fool proof (note however that i didn't test strings such as 100d to 10000 because there is validation to be sure of that)
Thanks in advance!
NOTE: i did do some googling and searching and i dont think it is covered by any question here, yes some are similar but they are concerned about not wanting numbers in the string, not wanting a string of only numbers, so i deemed this different enough to post.
Note 2: My specific question is where will numeric comparisons fail when using strings of numbers instead of ints