Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK

## java.lang
Class Number

Method Summary
`int` | `abs()` Get the absolute value
`Number` | `and(Number right)` Bitwise AND together two Numbers
`Object` | `asType(Class c)` Transform this number to a the given type, using the 'as' operator following types are supported in addition to the default {@link #asType(Object,Class)}: BigDecimal BigInteger Double Float
`int` | `compareTo(Character right)` Compare a Number and a Character digit (i representation
`int` | `compareTo(Number right)` Compare two Numbers
`Number` | `div(Character right)` Divide a Number by a Character digit (i representation
`Number` | `div(Number right)` Divide two Numbers
`void` | `downto(Number to, Closure closure)` Iterates from this number down to the given number, inclusive, decrementing by one each time
`Number` | `intdiv(Character right)` Integer Divide a Number by a Character
`Number` | `intdiv(Number right)` Integer Divide two Numbers
`boolean` | `isCase(Number switchValue)` Special 'case' implementation for all numbers, which delegates to the `compareTo()` method for comparing numbers of different types
`Number` | `leftShift(Number operand)` Implementation of the left shift operator for integral types Number types throw UnsupportedOperationException
`Number` | `minus(Character right)` Subtract a Character from a Number digit (i representation
`Number` | `minus(Number right)` Substraction of two Numbers
`Number` | `mod(Number right)` Performs a division modulus operation
`Number` | `multiply(Character right)` Multiply a Number by a Character digit (i representation
`Number` | `multiply(Number right)` Multiply two Numbers
`Number` | `next()` Increment a Number by one
`Number` | `or(Number right)` Bitwise OR together two numbers
`String` | `plus(String right)` Appends a String to the string representation of this number
`Number` | `plus(Character right)` Add a Number and a Character digits '0' through '9'
`Number` | `plus(Number right)` Add two numbers and return the result
`Number` | `power(Number exponent)` Power of a Number to a certain exponent
`Number` | `previous()` Decrement a Number by one
`Number` | `rightShift(Number operand)` Implementation of the right shift operator for integral types Number types throw UnsupportedOperationException
`Number` | `rightShiftUnsigned(Number operand)` Implementation of the right shift (unsigned) operator for integral types Number types throw UnsupportedOperationException
`void` | `step(Number to, Number stepNumber, Closure closure)` Iterates from this number up to the given number using a step increment Each intermediate number is passed to the given closure
    0
    println it
    }
Prints even numbers 0 through 8
`void` | `times(Closure closure)` Executes the closure this many times, starting from zero index is passed to the closure each time Example:
    10
    println it
    }
Prints the numbers 0 through 9
`BigDecimal` | `toBigDecimal()` Transform a Number into a BigDecimal
`BigInteger` | `toBigInteger()` Transform this Number into a BigInteger
`Double` | `toDouble()` Transform a Number into a Double
`Float` | `toFloat()` Transform a Number into a Float
`Integer` | `toInteger()` Transform a Number into an Integer
`Long` | `toLong()` Transform a Number into a Long
`Number` | `unaryMinus()` Negates the number a single operand, i
`void` | `upto(Number to, Closure closure)` Iterates from this number up to the given number, inclusive, incrementing by one each time
`Number` | `xor(Number right)` Bitwise XOR together two Numbers

Method Detail

### abs

    public int abs()

  Get the absolute value

Returns:
  the absolute value of that Number

### and

    public Number and(Number right)

  Bitwise AND together two Numbers.

Parameters:
  `right` - another Number to bitwise AND.
Returns:
  the bitwise AND of both Numbers

### asType

    public Object asType(Class c)

  Transform this number to a the given type, using the 'as' operator. The following types are supported in addition to the default {@link #asType(Object,Class)}:
  - BigDecimal
  - BigInteger
  - Double
  - Float

Parameters:
  `c` - the desired type of the transformed result.
Returns:
  an instance of the given type

### compareTo

    public int compareTo(Character right)

  Compare a Number and a Character. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
  `right` - a Character.
Returns:
  the result of the comparison

### compareTo

    public int compareTo(Number right)

  Compare two Numbers. Equality (==) for numbers dispatches to this.

Parameters:
  `right` - another Number to compare to.
Returns:
  the comparision of both numbers

### div

    public Number div(Character right)

  Divide a Number by a Character. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
  `right` - a Character.
Returns:
  the multiplication of both

### div

    public Number div(Number right)

  Divide two Numbers.

Parameters:
  `right` - another Number.
Returns:
  a Number resulting of the divide operation

### downto

    public void downto(Number to, Closure closure)

  Iterates from this number down to the given number, inclusive, decrementing by one each time.

Parameters:
  `to` - another Number to go down to.
  `closure` - the closure to call.

### intdiv

    public Number intdiv(Character right)

  Integer Divide a Number by a Character.

Parameters:
  `right` - a Character.
Returns:
  the integer division of both

### intdiv

    public Number intdiv(Number right)

  Integer Divide two Numbers.

Parameters:
  `right` - another Number.
Returns:
  a Number (an Integer) resulting of the integer division operation

### isCase

    public boolean isCase(Number switchValue)

  Special 'case' implementation for all numbers, which delegates to the `compareTo()` method for comparing numbers of different types.

Parameters:
  `switchValue` - the switch value.
Returns:
  true if the numbers are deemed equal

### leftShift

    public Number leftShift(Number operand)

  Implementation of the left shift operator for integral types. Non integral Number types throw UnsupportedOperationException.

Parameters:
  `operand` - the shift distance by which to left shift the number.
Returns:
  the resulting number

### minus

    public Number minus(Character right)

  Subtract a Character from a Number. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
  `right` - a Character.
Returns:
  the addition of the Character and the Number

### minus

    public Number minus(Number right)

  Substraction of two Numbers.

Parameters:
  `right` - another Number to substract to the first one.
Returns:
  the substraction

### mod

    public Number mod(Number right)

  Performs a division modulus operation. Called by the '%' operator.

Parameters:
  `right` - another Number to mod.
Returns:
  the modulus result

### multiply

    public Number multiply(Character right)

  Multiply a Number by a Character. The character is assumed to be a digit (i.e. '0' through '9') which is converted to its Integer representation.

Parameters:
  `right` - a Character.
Returns:
  the multiplication of both

### multiply

    public Number multiply(Number right)

  Multiply two Numbers.

Parameters:
  `right` - another Number.
Returns:
  the multiplication of both

### next

    public Number next()

  Increment a Number by one.

Returns:
  an incremented Number

### or

    public Number or(Number right)

  Bitwise OR together two numbers.

Parameters:
  `right` - another Number to bitwise OR.
Returns:
  the bitwise OR of both Numbers

### plus

    public String plus(String right)

  Appends a String to the string representation of this number.

Parameters:
  `right` - a String.
Returns:
  a String

### plus

    public Number plus(Character right)

  Add a Number and a Character. This assumes the character is one of the digits '0' through '9'.

Parameters:
  `right` - a Character.
Returns:
  The Number corresponding to the addition of left and right

See:
  Integer#valueOf(String).

### plus

    public Number plus(Number right)

  Add two numbers and return the result.

Parameters:
  `right` - another Number to add.
Returns:
  the addition of both Numbers

### power

    public Number power(Number exponent)

  Power of a Number to a certain exponent. Called by the '**' operator.

Parameters:
  `exponent` - a Number exponent.
Returns:
  a Number to the power of a certain exponent

### previous

    public Number previous()

  Decrement a Number by one.

Returns:
  a decremented Number

### rightShift

    public Number rightShift(Number operand)

  Implementation of the right shift operator for integral types. Non integral Number types throw UnsupportedOperationException.

Parameters:
  `operand` - the shift distance by which to right shift the number.
Returns:
  the resulting number

### rightShiftUnsigned

    public Number rightShiftUnsigned(Number operand)

  Implementation of the right shift (unsigned) operator for integral types. Non integral Number types throw UnsupportedOperationException.

Parameters:
  `operand` - the shift distance by which to right shift (unsigned) the number.
Returns:
  the resulting number

### step

    public void step(Number to, Number stepNumber, Closure closure)

  Iterates from this number up to the given number using a step increment. Each intermediate number is passed to the given closure. Example:

      0.step( 10, 2 ) {
      println it
      }

  Prints even numbers 0 through 8.

Parameters:
  `to` - a Number to go up to, exclusive.
  `stepNumber` - a Number representing the step increment.
  `closure` - the closure to call.

### times

    public void times(Closure closure)

  Executes the closure this many times, starting from zero. The current index is passed to the closure each time. Example:

      10.times {
      println it
      }

  Prints the numbers 0 through 9.

Parameters:
  `closure` - the closure to call a number of times.

### toBigDecimal

    public BigDecimal toBigDecimal()

  Transform a Number into a BigDecimal

Returns:
  an BigDecimal

### toBigInteger

    public BigInteger toBigInteger()

  Transform this Number into a BigInteger.

Returns:
  an BigInteger

### toDouble

    public Double toDouble()

  Transform a Number into a Double

Returns:
  an Double

### toFloat

    public Float toFloat()

  Transform a Number into a Float

Returns:
  an Float

### toInteger

    public Integer toInteger()

  Transform a Number into an Integer

Returns:
  an Integer

### toLong

    public Long toLong()

  Transform a Number into a Long

Returns:
  an Long

### unaryMinus

    public Number unaryMinus()

  Negates the number. Equivalent to the '-' operator when it preceeds a single operand, i.e. `-10`

Returns:
  the negation of the number

### upto

    public void upto(Number to, Closure closure)

  Iterates from this number up to the given number, inclusive, incrementing by one each time.

Parameters:
  `to` - another Number to go up to.
  `closure` - the closure to call.

### xor

    public Number xor(Number right)

  Bitwise XOR together two Numbers. Called when the '|' operator is used.

Parameters:
  `right` - another Number to bitwse XOR.
Returns:
  the bitwise XOR of both Numbers

Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK