Conversion from integer/floating-point to string

Please tell me how can I convert integers such as 5,7,89,etc. or floating-ppoints like 5.90,7.45,etc. to strings like “5”,“5.90”,etc.

Hello Anupam, it’s very easy to convert …take a look at this code below.

class Conversion{

     public static void main(String args[]){
                int x= 2;

                float y = 2.95;

                String str_int = 2+""; 

                String str_float = 2.95+"";

               //now you can print it..

                System.out.println("Int to  String "+str_int+" Float to String "+str_float);



This might be of your use, NjqIMR - Online C++0x Compiler & Debugging Tool - Jst using basic sprintf() function.

As I am new to the site, I did not see what language you wanted this in so I am going to post what I would do in C++. Since C++ 11 has a new function of putting things to strings, see code below, it is easier to convert things now!

#include <string>

int a = 12;
float b = 3.1459;
std::string str = to_string(a);
std::string str2 = to_string(b);

I want the code in c++4.3.2