

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to convert Double to numeric primitive data types
Let’s say we have Double object here.
Double obj = new Double("39.45");
Now, if we want to convert this Double to short primitive data type. For that, use the in-built shortValue() method.
// converting to short primitive types short shortObj = obj.shortValue(); System.out.println(shortObj);
In the same way convert Double to another numeric primitive data type int. For that, use the in-built intValue() method.
// converting to int primitive types int intObj = obj.intValue(); System.out.println(intObj);
The following is an example wherein we convert Double to numeric primitive types short, int, float, etc.
Example
public class Demo { public static void main(String args[]) { Double obj = new Double("39.45"); int intVal = obj.intValue(); System.out.println(intVal); byte byteVal = obj.byteValue(); System.out.println(byteVal); short shortVal = obj.shortValue(); System.out.println(shortVal); float floatVal = obj.floatValue(); System.out.println(floatVal); double doubleVal = obj.doubleValue(); System.out.println(doubleVal); } }
Output
39 39 39 39.45 39.45
- Related Questions & Answers
- Java Program to convert Java Float to Numeric Primitive Data Types
- Convert Byte to numeric primitive data types in Java
- Convert Short to numeric primitive data types in Java
- Convert Long to numeric primitive data types in Java
- Java primitive data types
- Convert double primitive type to a Double object in Java
- List out the default values of numeric and non-numeric primitive data types in Java?
- How to convert JavaScript objects to primitive data types manually?
- Java Program to convert a string into a numeric primitive type using Integer.valueOf()
- Comparison of double and float primitive types in Java
- What are primitive data types in Java?
- Java Program to convert String to short primitive
- Java Program to convert String to Double
- Uninitialized primitive data types in C/C++ Program
- Default value of primitive data types in Java
Advertisements