Provides large/precise number support
1.0.0b3 | Added the $remove_zero_fraction parameter to format() 2/2/11 |
---|---|
1.0.0b2 | Fixed a bug with parsing decimal numbers in scientific notation 4/13/10 |
1.0.0b | The initial implementation 7/21/08 |
Converts any positive integer between any two bases ranging from 2 to 16
string baseConvert( fNumber|string $number, integer $from_base, integer $to_base )
fNumber|string | $number | The positive integer to convert |
integer | $from_base | The base to convert from - must be between 2 and 16 |
integer | $to_base | The base to convert to - must be between 2 and 16 |
The number converted to the new base
Returns the value for pi with a scale of up to 500
fNumber pi( integer $scale )
integer | $scale | The number of places after the decimal to return |
Pi
Allows setting a callback to translate or modify any return values from format()
The callback should accept two parameters:
The callback should return a string, the formatted $value.
void registerFormatCallback( callback $callback )
callback | $callback | The callback to pass the fNumber value to - see method description for parameters |
Allows setting a callback to clean any formatted values so they can be properly parsed - useful for languages where , is used as the decimal point
void registerUnformatCallback( callback $callback )
callback | $callback | The callback to pass formatted strings to. Should accept a formatted string and return a string the is a valid number using . as the decimal point. |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
void reset( )
Creates a large/precise number
fNumber __construct( string $value, integer $scale=NULL )
string | $value | The value for the number - any valid PHP integer or float format including values with e exponents |
integer | $scale | The number of digits after the decimal place, defaults to number of digits in $value |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
All requests that hit this method should be requests for callbacks
callback __get( string $method )
string | $method | The method to create a callback for |
The callback for the method requested
Converts the object to an string
string __toString( )
Returns the absolute value of this number
fNumber abs( integer $scale=NULL )
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The absolute number
Adds two numbers together
fNumber add( fNumber|string $addend, integer $scale=NULL )
fNumber|string | $addend | The addend |
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The sum
Rounds the number to the next highest integer
fNumber ceil( )
The next highest integer
Divides this number by the one passed
fNumber div( fNumber|string $divisor, integer $scale=NULL )
fNumber|string | $divisor | The divisor |
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The quotient
Indicates if this value is equal to the one passed
boolean eq( fNumber|string $number, integer $scale=NULL )
fNumber|string | $number | The number to compare to |
integer | $scale | The number of decimal places to compare - will use all available if not specified |
If this number is equal to the one passed
Rounds the number to the next lowest integer
fNumber floor( )
The next lowest integer
Returns the float remainder of dividing this number by the divisor provided
fNumber fmod( fNumber|string $divisor, integer $scale=NULL )
fNumber|string | $divisor | The divisor |
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The remainder
Formats the number to include thousands separators
string format( boolean $remove_zero_fraction=FALSE )
boolean | $remove_zero_fraction | If TRUE and all digits after the decimal place are 0, the decimal place and all zeros are removed |
The formatted value
Returns the scale of this number
integer getScale( )
The scale of this number
Indicates if this value is greater than the one passed
boolean gt( fNumber|string $number, integer $scale=NULL )
fNumber|string | $number | The number to compare to |
integer | $scale | The number of decimal places to compare - will use all available if not specified |
If this number is less than the one passed
Indicates if this value is greater than or equal to the one passed
boolean gte( fNumber|string $number, integer $scale=NULL )
fNumber|string | $number | The number to compare to |
integer | $scale | The number of decimal places to compare - will use all available if not specified |
If this number is greater than or equal to the one passed
Indicates if this value is less than the one passed
boolean lt( fNumber|string $number, integer $scale=NULL )
fNumber|string | $number | The number to compare to |
integer | $scale | The number of decimal places to compare - will use all available if not specified |
If this number is less than the one passed
Indicates if this value is less than or equal to the one passed
boolean lte( fNumber|string $number, integer $scale=NULL )
fNumber|string | $number | The number to compare to |
integer | $scale | The number of decimal places to compare - will use all available if not specified |
If this number is less than or equal to the one passed
Returns the remainder of dividing this number by the divisor provided. All floats are converted to integers.
fNumber mod( fNumber|string $divisor )
fNumber|string | $divisor | The divisor - will be converted to an integer if it is a float |
The remainder
Multiplies two numbers
fNumber mul( fNumber|string $multiplier, integer $scale=NULL )
fNumber|string | $multiplier | The multiplier |
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The product
Negates this number
fNumber neg( integer $scale=NULL )
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The negated number
Raise this number to the power specified
fNumber pow( integer $exponent, integer $scale=NULL )
integer | $exponent | The power to raise to - all non integer values will be truncated to integers |
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The product
Gets the remainder of this integer number raised to the integer $exponent, divided by the integer $modulus
This method is faster than doing $num->pow($exponent)->mod($modulus) and is primarily useful for cryptographic functionality.
fNumber powmod( fNumber|string $exponent, fNumber|string $modulus )
fNumber|string | $exponent | The power to raise to - all non integer values will be truncated to integers |
fNumber|string | $modulus | The value to divide by - all non integer values will be truncated to integers |
The remainder
Rounds this number to the specified number of digits after the decimal - negative scales round the number by places to the left of the decimal
fNumber round( integer $scale )
integer | $scale | The number of places after (or before if negative) the decimal to round to |
The rounded result
Returns the sign of the number
integer sign( )
-1 if negative, 0 if zero, 1 if positive
Returns the square root of this number
fNumber sqrt( integer $scale=NULL )
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The square root
Subtracts two numbers
fNumber sub( fNumber|string $subtrahend, integer $scale=NULL )
fNumber|string | $subtrahend | The subtrahend |
integer | $scale | The number of places after the decimal - overrides the scale for this number |
The difference
Scales (truncates or expands) the number to the specified number of digits after the decimal - negative scales round the number by places to the left of the decimal
fNumber trunc( integer $scale )
integer | $scale | The number of places after (or before if negative) the decimal |
The square root