Function Math Arithmetic Class

IsPrime

"Is Number Prime" Return true if a number is prime; return False otherwise.

Signature (Visual Basic / VBA)

Public Function IsPrime( _
    ByVal vNumber As Variant _
    ) As Boolean

Code Example

    IsPrime(0) = False
    IsPrime(1) = False
    IsPrime(2) = True
    IsPrime(3) = True
    IsPrime(4) = False
    IsPrime(5) = True
    IsPrime(4.76) = True ' #7
    IsPrime(-5) = True ' #8

Parameters

Parameter Description
vNumber The number which is tested to see if it is prime. Function returns Null if vNumber is Null or cannot be fixed up to a number.

Notes & Version History

Warning The floating-point part of vNumber (if any) is ignored as in example #7.
Note Function uses the absolute value of the number to determine if it is prime as in example #8.