char c='a';
NSLog(@"%c",c);
NSString *ns=@"NSString";
NSLog(@"%@",ns);
char *s="String";
NSLog(@"%s",s);
NSLog(@"%c",'A');
NSLog(@"%c",65);
Output will look like following in console window :
2011-08-09 21:16:50.468 MIMTextLib[17207:207] a
2011-08-09 21:16:50.470 MIMTextLib[17207:207] NSString
2011-08-09 21:16:50.472 MIMTextLib[17207:207] String
2011-08-09 21:16:50.474 MIMTextLib[17314:207] A
2011-08-09 21:16:50.776 MIMTextLib[17314:207] A
//To print integer/decimal
int p=10;
NSLog(@"%i",p);
NSInteger l=10;
NSLog(@"%d",l);2011-08-09 21:24:23.672 MIMTextLib[17254:207] 10
2011-08-09 21:24:23.673 MIMTextLib[17254:207] 10
//To print float
float f=10;
NSLog(@"%f",f);
//Upto 2 places of decimal
float f2=10;
NSLog(@"2 places of decimal=%0.2f",f2);
//Upto 1 places of decimal
float f1=10;
NSLog(@" 1 places of decimal= %0.1f",f1);
//Upto 0 places of decimal
float f0=10;
NSLog(@"0 places of decimal =%0.0f",f0);2011-08-09 21:24:23.673 MIMTextLib[17254:207] 10.000000
2011-08-09 21:24:23.674 MIMTextLib[17254:207] 2 places of decimal=10.00
2011-08-09 21:24:23.674 MIMTextLib[17254:207] 1 places of decimal= 10.0
2011-08-09 21:24:23.675 MIMTextLib[17254:207] 0 places of decimal =10 //To print double
double d=10;
NSLog(@"%lf",d);
//You can apply %0.1lf to get upto 1 place of decimal, just like we did for float2011-08-09 21:24:23.675 MIMTextLib[17254:207] 10.000000
//Preceding with zeros
NSLog(@"%008d",666);
NSLog(@"%008d",666);
NSLog(@"%003d",666);
NSLog(@"%010d",666);2011-08-09 21:32:25.398 MIMTextLib[17419:207] 00000666
2011-08-09 21:32:25.400 MIMTextLib[17419:207] 666
2011-08-09 21:32:25.401 MIMTextLib[17419:207] 0000000666
//Preceding with blanks
printf ("Preceding with blanks: %10d \n", 1977);de
printf ("Preceding with blanks: %10d \n", 1977);de
Preceding with blanks: 1977
No comments:
Post a Comment