SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    logic help: Check if 3 currency types are larger than another set of 3

    I need help checking against user input for gold, silver, and copper

    ex:
    current price is 5g, 0s, 0c
    offered price is 4g, 9999999s, 99999c

    the user's offer should be rejected.

  2. #2
    Team SitePoint Lucas Chan's Avatar
    Join Date
    Sep 2002
    Location
    Melbourne
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could pad the silver and copper values with 0's, then join all parts together to test for the greater integer?

    $s = str_pad($s, 2, '0', STR_PAD_LEFT);
    $c = str_pad($c, 2, '0', STR_PAD_LEFT);

    i.e.

    5g, 0s, 0c would become 5g, 00s, 00c, which becomes 50000, which is greater than 49999.

    Or something like that. =)

  3. #3
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what about if the silver and copper offer were 999999999999

  4. #4
    Team SitePoint Lucas Chan's Avatar
    Join Date
    Sep 2002
    Location
    Melbourne
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by GeekSupport
    what about if the silver and copper offer were 999999999999
    Then, my answer looks stupid because you just changed/edited your original question.

    =)

    Without going into some sort of extended rant, the only other way I can think of is to use a complex set of if statements.

    Not particularly elegant though.

  5. #5
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry about that Lucas Chan

    i just thought about my "9999999" question and it wouldn't realistically make any sence (999999 silver should be > 1 gold).

    maybe =$g+$s/100+$c/1000 will work if it takes 100s = 1g and 1000c = 1g

    Edit:


    maybe not (4,99,99 is 5.089)

    Edit:


    oops, it'a actually 10,000c = 1g so it'll work out fine

    1 + 1/100 + 1/10000


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •