How can you Earn 30 Dollar Daily ? Click to see the Earning Ways.
Login(Email) Password Forgot Password
Home ASP.net System Info C# Books Java Script Visual C++(MFC) C/C++ Win API Java Contact Us
Browse Category
How to Convert String (Char array ) in C/C++ to Integer, long and Double
char a[]="123";
char b[]="123.66";
//for interger
int i=atoi(a);
//for Long
long l=atol(a);
//for double
float d=atof(b);
How to Convert Integer with different base type like (decimal,hexadecimal and Binary) to String(Char Array)
#include <stdlib.h>
#include <iostream.h>
main()
{
int val;
char st[10] val = 1772;
 itoa(val,st,10) //base 10
cout <<"decimal: "<<st<<endl;
itoa(val,st,16) //hexidecimal
cout <<"hexidecimal: "<< st << endl;
iota(val,st,2); //binary conversion
cout<<"Binary: "<<st<<endl;
}
How to write formatted data to string in C/C++ and QT(Also you can use this function to write the number in C/C++ as well in QT)
#include < conio.h >
#include < stdio.h >
#include < iostream.h >
void main()
{
clrscr();
float mm =3.888;
char str[10];
sprintf(str,"%.2f",mm); // will print upto 2 decimal
sprintf(str,"%.3f",mm);// will print upto 3 decimal
sprintf(str,"%.0f",mm); //will round the number;
cout<<str;
getche();
}