- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Advertisements