- Groovy Tutorial
- Groovy - Home
- Groovy - Overview
- Groovy - Environment
- Groovy - Basic Syntax
- Groovy - Data Types
- Groovy - Variables
- Groovy - Operators
- Groovy - Loops
- Groovy - Decision Making
- Groovy - Methods
- Groovy - File I/O
- Groovy - Optionals
- Groovy - Numbers
- Groovy - Strings
- Groovy - Ranges
- Groovy - Lists
- Groovy - Maps
- Groovy - Dates & Times
- Groovy - Regular Expressions
- Groovy - Exception Handling
- Groovy - Object Oriented
- Groovy - Generics
- Groovy - Traits
- Groovy - Closures
- Groovy - Annotations
- Groovy - XML
- Groovy - JMX
- Groovy - JSON
- Groovy - DSLS
- Groovy - Database
- Groovy - Builders
- Groovy - Command Line
- Groovy - Unit Testing
- Groovy - Template Engines
- Groovy - Meta Object Programming
- Groovy Useful Resources
- Groovy - Quick Guide
- Groovy - Useful Resources
- Groovy - Discussion
Groovy - xxxValue()
This method takes on the Number as the parameter and returns a primitive type based on the method which is invoked. Following are the list of methods available −
byte byteValue() short shortValue() int intValue() long longValue() float floatValue() double doubleValue()
Parameters − No parameters required.
Return Value − The return value is the primitive type returned depending on the value function which is called.
Example
Following is an example of the usage of the method values.
class Example { static void main(String[] args) { Integer x = 5; // Converting the number to double primitive type println(x.doubleValue()); // Converting the number to byte primitive type println(x.byteValue()); // Converting the number to float primitive type println(x.floatValue()); // Converting the number to long primitive type println(x.longValue()); // Converting the number to short primitive type println(x.shortValue()); // Converting the number to int primitive type println(x.intValue()); } }
When we run the above program, we will get the following result −
5.0 5 5.0 5 5 5
groovy_numbers.htm
Advertisements