Search This Blog

Friday, 12 December 2014

String to float conversation and float to String conversation

Conversation from String to float and float to String is so easy. Java provide below method for conversation.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
public class Main {

 public static void main(String args[]) {  

  /**
   * String to float conversation
   */
  String strVar="123.45";
  float f=Float.parseFloat(strVar);
  System.out.println("Floar variable="+f);

  /**
   * float to String conversation
   */
  strVar=String.valueOf(f);
  System.out.println("String varibale="+f);
 }
}

OutPut
Floar variable=123.45
String varibale=123.45

No comments:

Post a Comment