Download the PHP package madbyad/mpl-number-converter without Composer
On this page you can find all versions of the php package madbyad/mpl-number-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download madbyad/mpl-number-converter
More information about madbyad/mpl-number-converter
Files in madbyad/mpl-number-converter
Package mpl-number-converter
Short Description A simple PHP library used for number conversion
License MIT
Informations about the package mpl-number-converter
MPL Number Converter
The MPL (MadByAd PHP Library) Number Converter is a simple PHP library which is used for number conversion and others such as converting a number to a roman numeral e.g 12
to XII
, abbreviating a number e.g 25.690
to 25.6K
, formatting a number e.g 1000000
to 1.000.000
and other number manipulation function.
- MPL Number Converter
- Installation
- Abbreviating Number
- Formating Number
- Alphabet Conversion
- Binary Conversion
- Hexadecimal Conversion
- Octal Conversion
- Roman Conversion
Installation
to install the package go ahead and open composer then write the command
Abbreviating Number
To abbreviate or deabbreviate number you can use the numberToAbbreviate
or abbreviateToNumber
method.
The numberToAbbreviate(int $number, int $precision = 1, array $symbolSet = null)
method is used for shortening long integer, it takes 3 parameter, first is the integer to convert, second is to determine the precision (how many digit behind decimal point) and the last is the symbol set which is the symbol to use when the number is higher than a certain digit. To define a custom symbolSet the parameter must be an associative array where the key represent the digit count and the value corresponds to the symbol to use.
Example 1
output
Example 2
output
The abbreviateToNumber(string $abbreviatedNumber, array $symbolSet = null)
method is used for deabreviating abbreviated number (converting an abbreviated int to a normal int), it takes 2 parameter, first is the abbreviated number and the second is the symbol set which is the symbol to use when the number is higher than a certain digit. To define a custom symbolSet the parameter must be an associative array where the key represent the digit count and the value corresponds to the symbol to use.
Example 1
output
Example 2
output
Formating Number
To format or unformat a number you can use the numberToFormat
and formatToNumber
method
The numberToFormat(int $integer, string $separatorStyle = ".")
method is used for formatting number (so it can be easily read especially for long digit number), it takes 2 parameter, first is the integer number and second is the separator style which determine what kind of separator you want to use, by default its .
but you change it to anything except a-z
A-Z
0-9
and it must be a 1 character long string
Example
output
The formatToNumber(string $formattedInt)
method is used for unformatting a number (converting a formatted integer which is in a form of string into a normal integer), it takes only 1 parameter and that is the formatted integer string
Example
output
Alphabet Conversion
To convert a number to an alphabet or the opposite, you can use the numberToAlphabet
and the alphabetToNumber
method
The numberToAlphabet(int $number, bool $uppercase = true)
method is used for converting a number to an alphabet (usefull for making alphabetically ordered list), it takes only 2 parameter, first is the integer and the second is to determine whether should the letter be uppercase or lowercase.
Example
output
The alphabetToNumber(string $alphabet)
method is used for converting an alphabet string into its integer value, it only takes 1 parameter and that is the alphabet string
Example
output
Binary Conversion
To convert a number to a binary and the opposite, you can use the numberToBinary
and binaryToNumber
method
The numberToBinary(int $number)
method is used for converting an integer to a binary string, it takes 1 parameter and that is the number
Example
output
The binaryToNumber(string $binary)
method is used for converting a binary string to an integer, it takes 1 parameter and that is the binary string
Example
output
Hexadecimal Conversion
To convert a number to a hexadecimal string and the opposite, you can use the numberToHexadecimal
and hexadecimalToNumber
method
The numberToHexadecimal(int $number, bool $uppercase = true)
method is used for converting a number to a hexadecimal string, it takes 2 parameter, first is the integer number, and the second is to determine whether the letter on the hexadecimal string should be uppercased or lowercased
Example
output
The hexadecimalToNumber(string $hexadecimal)
method is used for converting a hexadecimal string to an integer, it takes only 1 parameter and that is the hexadecimal string
Example
output
Octal Conversion
To convert a number to an octal or the opposite, you can use the numberToOctal
and octalToNumber
method
The numberToOctal(int $number)
method is used for converting a number to an octal, it takes only 1 parameter and that is the integer number
Example
output
The octalToNumber(string $octal)
method is used for converting an octal string to a number, it takes only 1 parameter and that is the octal string
Example
output
Roman Conversion
To convert a number to a roman numeral or the opposite, you can use the numberToRoman
and romanToNumber
method
The numberToRoman(int $number)
method is used for converting a number to a roman numeral (usefull for making list ordered with roman numeral), it takes only 1 parameter and that is the integer number
Example
output
The romanToNumber(string $roman)
method is used for converting a roman numeral to a number, it takes only 1 parameter and that is the roman numeral
Example
output