-
-
Notifications
You must be signed in to change notification settings - Fork 6
Helper Methods
The following helper methods are available on any class that implements NumberInterface
Returns the current value as a string. Note: This will return the current value in whatever the current base is.
Returns the base of the current value.
Returns true
if the number is less than 0, false
otherwise. Note: Zero is not considered negative.
Returns true
if the number is greater than 0, false
otherwise. Note: Zero is not considered positive.
Returns true
if the object and value are equal to each other, false
otherwise. Note: Does not round or truncate based on precision prior to comparison.
Returns true
if the object is greater than the value argument, false
otherwise. Note: Does not round or truncate based on precision prior to comparison.
Returns true
if the object is greater than or equal to the value argument, false
otherwise. Note: Does not round or truncate based on precision prior to comparison.
Returns true
if the object is less than the value argument, false
otherwise. Note: Does not round or truncate based on precision prior to comparison.
Returns true
if the object is less than or equal to the value argument, false
otherwise. Note: Does not round or truncate based on precision prior to comparison.
Returns 1
if the object is greater than the value argument, 0
if they are equal, and -1
if the object is less than the value argument. Note: Does not round or truncate based on precision prior to comparison.
Applies the absolute value function to the current object. Note: For Mutable objects, this method will alter the object.
Returns the absolute value of the current object as a string without altering the object.
Changes the base of the current object and converts its value to that base.
The following helper methods are available on any class that implements DecimalInterface
Returns the precision setting of the current object.
These methods are all aliases for the same question: does this number have numbers (other than zero) after the decimal place. It returns false
if there is, and true
if there is not.
Returns true
if the current object is a prime number, false
if it is not. Also returns false
if the number is not a whole number. Note: For very large primes, or composites with only very large prime factors, this method may be very slow.
Rounds the current object to the specified number of decimal places.
Truncates the current object to the specified number of decimal places.
Rounds the current object to the specified precision and sets the precision of the current object to that value.
Truncates the current object to the specified precision and sets the precision of the current object to that value.
Rounds the current object up to the nearest whole number.
Rounds the current object down to the nearest whole number.
Gives the remainder of the current object divided by the modulus, but the modulus must be a whole number.
Gives the remainder of the current object divided by the modulus to 100 digits, and the modulus can be a decimal number.
Returns the Least Common Multiple of the current object and the argument. The argument must be a whole number. Note: For Mutable objects, this method will modify the object.
Returns the Greatest Common Divisor of the current object and the argument. The argument must be a whole number. Note: This method will always return an ImmutableNumber
instance, and will never modify the current object.
This returns the number of zeros between the decimal point and the first non-zero number after the decimal place.
This converts the current object to base10 are returns the original base as an int. If the base was already 10, it returns false. This is useful in conjunction with convertFromModification()
to perform math of some kind of a number in a different base, since all math libraries for working with numbers expect the numbers to be in base10.
This converts the current object to the base supplied by the argument, or exits early if false
is supplied. This is the only method that will modify an ImmutableNumber
object in place without returning a new instance. This is useful in conjunction with convertForModification()
to perform math of some kind of a number in a different base, since all math libraries for working with numbers expect the numbers to be in base10.