Convert Integer to Float

In this section, you will learn to convert an integer type data into a float.


 

Ads

Tutorials   
Ads

Convert Integer to Float

     

In this section, you will learn to convert an integer type data into a float. The following programs helps you in converting an integer into a float type data. 

Code Description:

This program takes an integer number at console  and it converts into a float type data using the toString() method. This method specified the string value signed an integer which is converted into a float format.

toString():  This method converts an integer into a float and returns a float object. 

Here is the code of this program:

import java.io.*;
import java.lang.*;

public class  IntegerToFloat {
  public static void main(String[] argsthrows IOException{
  BufferedReader read = 
  new 
BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter a integer value!");
  String str = read.readLine();
  Integer i = new Integer (str);
  String s = new Float(i).toString();
  System.out.println ("Float:=" + s
  }
}

Download this program: 

Output this program.

C:\corejava>java IntegerToFloat
Enter a integer value!
24
Float:=24.0
C:\corejava> _

 

Advertisements

Share on Google+Share on Google+

Convert Integer to Float

Posted on: July 4, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Convert Integer to Float   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
VINOD TIWARI
June 5, 2011
CONVERT INTEGER INTO FLOAT AND DOUBLE

PLEASE GIVE ME SOLUTION BY C PROGRAM: MAKE A C PROGRAM IN WHICH INTEGER CONVERT INTO FLOAT AND DOUBLE.
Ravindra Munde
August 15, 2012
How to convert integer value to float value in c

I want the c program to find the conversion of integer value in float value

Ads

 

Ads