1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Duration number on Numeric

Discussion in 'Help' started by NZSigourney, Aug 28, 2021.

  1. NZSigourney

    NZSigourney Silverfish

    Messages:
    23
    GitHub:
    NZSigourney
    How To make a Code like "If(!is_numeric($args[0]))" then If The number is pass over 12 Number then "Lower 12 !"?
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    In the example you've shown, you check if the given value is NOT numeric. After that, you can write another if statement to check if the value is lower and/or higher using PHP comparison operators (they are basically the same as in most programming languages).

    See example
    PHP:
    $givenValue $args[0];

    if(!
    is_numeric($givenValue)) {
        
    // Given value is not numeric, notify sender
        
    return; // to stop code execution
    }

    $givenValue = (int) $givenValue// Cast it to integer, or float if necessary (both are numeric values)
    // Casting it to integer with given float string, then decimals will be dropped

    // Perform comparison
    if($givenValue 12) {
        
    $sender->sendMessage('Given value was higher than twelve');
    }
    if(
    $givenValue 12) {
        
    $sender->sendMessage('Given value was lower than twelve');
    }
    if(
    $givenValue === 12) {
        
    $sender->sendMessage('Given value is identical 12');
    }

    // Statements above cover three possible states, meaning that one of the sendMessage methods will be called.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.