- 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 Java Float to Numeric Primitive Data Types
Let us first declare a Float object.
Float ob = new Float("29.35");
Now, let us convert it to numeric primitive data type short using shortValue()
short val1 = ob.shortValue();
In the same way, we can convert it to int using intValue() method.
short val1 = ob.intValue();
The following is an example that converts Float to other numeric primitive data types as well.
Example
public class Demo { public static void main(String args[]) { Float ob = new Float("29.35"); // numeric primitive data types short val1 = ob.shortValue(); System.out.println(val1); int val2 = ob.intValue(); System.out.println(val2); float val3 = ob.floatValue(); System.out.println(val3); double val4 = ob.doubleValue(); System.out.println(val4); } }
Output
29 29 29.35 29.350000381469727
- Related Articles
- Java Program to convert Double 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
- Java primitive data types
- 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 Program to convert String to short primitive
- Java Program to convert Java String to Float Object
- Java Program to convert float to String
- Comparison of double and float primitive types in Java\n
- C++ Program to convert primitive types to objects
- What are primitive data types in Java?
- Program to convert Primitive Array to Stream in Java
- How to convert JavaScript objects to primitive data types manually?

Advertisements