-2

I'm searching for a commant for a question.

I have a 4 digit number like 3521, and the question is i need to find numbers where the first two digit is bigger then the last two.

4 Answers4

1

Assuming your number is lnMyNumber:

lnMyNumber = 3521
? (Val(Left(Str(lnMyNumber, 4, 0),2)) > Val(right(Str(lnMyNumber, 4, 0),2)))
Stefan Wuebbe
  • 2,109
  • 5
  • 17
  • 28
Alan B
  • 4,086
  • 24
  • 33
0

Command Window example:

LOCAL unknownType
unknownType = 3521
? CompareSumsOfTwoBytePairs(unknownType) && returns true
unknownType = "3521"
? CompareSumsOfTwoBytePairs(unknownType) && returns true
unknownType = "YZAB"
? CompareSumsOfTwoBytePairs(unknownType) && returns true
unknownType = 35210
? CompareSumsOfTwoBytePairs(unknownType) && too long, returns false
* The following unexpected types return all false:
unknownType = .F.
? CompareSumsOfTwoBytePairs(unknownType)
unknownType = .Null.
? CompareSumsOfTwoBytePairs(unknownType)
unknownType = CREATEOBJECT("Form")
? CompareSumsOfTwoBytePairs(unknownType)
unknownType = DATE(2015, 2, 7)
? CompareSumsOfTwoBytePairs(unknownType)

FUNCTION CompareSumsOfTwoBytePairs(u)
    LOCAL c
    c = TRANSFORM(u)
    RETURN LEN(c) == 4 AND (SUBSTR(c, 1, 2) > SUBSTR(c, 3, 2))
ENDFUNC
Stefan Wuebbe
  • 2,109
  • 5
  • 17
  • 28
0

Another option is to keep the numbers as numbers vs forced string conversions.

n = 3521
? INT( n/100 ) > n-(INT(n/100)*100)

n/100 = 35.21... the int leaves just 35

and this same basis is in the other half...

n-(INT(n/100)*100)
3521 - ( INT( 3521/100) * 100 )
= 3521 - (  35 * 100 )
= 3521 - 3500 = 21

so 35 > 21
DRapp
  • 47,638
  • 12
  • 72
  • 142
0

This is a complete code than you can put in a function

    local lnVal, llReturn

    lnVal=35821

    llReturn=left(trans(lnVal),2)>right(trans(lnVal),2)

    return llReturn
Albert Català
  • 2,026
  • 2
  • 29
  • 35
  • 2
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Bono Mar 16 '15 at 12:56