Number


Class: \Flextype\Component\Number\Number

Visibility Function
public static between(float $minimum, float $maximum, float $value) : bool
Checks if the value is between the minimum and maximum (min & max included). if (Number::between(2, 10, 5)) { // do something... }
public static byteFormat(int/\integer $bytes, int/\integer $decimals) : boolean/string
Converts a number of bytes to a human readable number by taking the number of that unit that the bytes will go into it. echo Num::format_bytes('204800'); // 200 kB echo Num::format_bytes('214901', 1); // 209.9 kB echo Num::format_bytes('2249010', 1); // 2.1 MB echo Num::format_bytes('badbyteshere'); // false
public static convertToBytes(\string $size=null) : float
Converts a file size number to a byte value. echo Number::convertToBytes('200K'); // 204800 echo Number::convertToBytes('5MiB'); // 5242880 echo Number::convertToBytes('2.5GB'); // 2684354560
public static even(int/\integer $value) : bool
Checks the value for an even number. if (Number::even(2)) { // do something... }
public static format(\string $string='', \string $format='') : string
Formats a number by injecting non-numeric characters in a specified format into the string in the positions they appear in the format. echo Number::format('1234567890', '(000) 000-0000'); // (123) 456-7890 echo Number::format('1234567890', '000.000.0000'); // 123.456.7890
public static formatExp(\string $string, \string $format=null) : string
Formats a credit card expiration string. Expects 4-digit string (MMYY). echo Number::formatExp('1234'); // 12-34 echo Number::formatExp('1234', '00/00'); // 12/34
public static formatPhone(\string $string='', \string $format=null) : string
Formats a phone number. echo Number::formatPhone('0612345678'); // (061) 234 5678 echo Number::formatPhone('0612345678', '(00) 000 000 00'); // (06) 123 456 78
public static greaterThan(float $minimum, float $value) : bool
Checks if the value is greather than a given minimum. if (Number::greaterThan(2, 10)) { // do something... }
public static maskString(\string $string='', \string $format='', \string $ignore=' ') : string
Transforms a number by masking characters in a specified mask format, and ignoring characters that should be injected into the string without matching a character from the original string (defaults to space). echo Number::maskString('1234567812345678', '****0000'); // ****5678 echo Number::maskString('1234567812345678', ' 0000'); // 5678 echo Number::maskString('1234567812345678', ' - - - 0000', ' -'); // - - - 5678
public static maskСreditСard(\string $string, \string $format=null) : string
Formats (masks) a credit card. echo Number::maskСreditСard('1234263583742938'); // 2938 echo Number::maskСreditСard('1234123412341234', '0000 '); // 1234 ****
public static maximum(int/\integer $maximum, int/\integer $value) : bool
Checks if the value is not greater than or equal a given maximum. if (Number::maximum(2, 10)) { // do something... }
public static minimum(int/\integer $minimum, int/\integer $value) : bool
Checks if the value is greater than or equal to a given minimum. if (Number::minimum(2, 10)) { // do something... }
public static odd(int/\integer $value) : bool
Checks the value for an odd number. if (Number::odd(2)) { // do something... }
public static quantity(int/\integer $num, int/\integer $decimals) : string
Converts a number into a more readable human-type number. echo Number::quantity(7000); // 7K echo Number::quantity(7500); // 8K echo Number::quantity(7500, 1); // 7.5K
public static smallerThan(int/\integer $maximum, int/\integer $value) : bool
Checks if the value is smaller than a given maximum. if (Number::smallerThan(2, 10)) { // do something... }
Language: en, ru