- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Java Program to convert Java Float to Numeric Primitive Data Types
- Convert Long to numeric primitive data types in Java
- Convert Byte to numeric primitive data types in Java
- Convert Short to numeric primitive data types in Java
- Convert double primitive type to a Double object in Java
- C++ Program to convert primitive types to objects
- List out the default values of numeric and non-numeric primitive data types in Java?
- Java Program to convert a string into a numeric primitive type using Integer.valueOf()
- Java primitive data types
- How to convert JavaScript objects to primitive data types manually?
- Comparison of double and float primitive types in Java
- Golang Program to Convert Numeric Data to Hexadecimal
- Java Program to convert String to short primitive
- Program to convert Primitive Array to Stream in Java
- Java Program to convert String to Double

Advertisements