Exemples d'utilisation des formats

mobilemode
              source C                       resultat

printf("|%d|\n",1234);                       	|1234|
printf("|%d|\n",-1234);                      	|-1234|
printf("|%+d|\n",1234);                      	|+1234|
printf("|%+d|\n",-1234);                     	|-1234|
printf("|% d|\n",1234);                      	| 1234|
printf("|% d|\n",-1234);                     	|-1234|
printf("|%x|\n",0x56ab);                     	|56ab|
printf("|%X|\n",0x56ab);                     	|56AB|
printf("|%#x|\n",0x56ab);                    	|0x56ab|
printf("|%#X|\n",0x56ab);                    	|0X56AB|
printf("|%o|\n",1234);                       	|2322|
printf("|%#o|\n",1234);                      	|02322|
                                             	
printf("|%10d|\n",1234);                     	|      1234|
printf("|%10.6d|\n",1234);                   	|    001234|
printf("|%.6d|\n",1234);                     	|001234|
printf("|%*.6d|\n",10,1234);                 	|    001234|
printf("|%*.*d|\n",10,6,1234);               	|    001234|
                                             	
printf("|%f|\n",1.234567890123456789e5);     	|123456.789012|
printf("|%.4f|\n",1.234567890123456789e5);   	|123456.7890|
printf("|%.20f|\n",1.234567890123456789e5);  	|123456.78901234567456413060|
printf("|%20.4f|\n",1.234567890123456789e5); 	|         123456.7890|
                                             	
printf("|%e|\n",1.234567890123456789e5);     	|1.234568e+05|
printf("|%.4e|\n",1.234567890123456789e5);   	|1.2346e+05|
printf("|%.20e|\n",1.234567890123456789e5);  	|1.23456789012345674564e+05|
printf("|%20.4e|\n",1.234567890123456789e5); 	|          1.2346e+05|
                                             	
printf("|%.4g|\n",1.234567890123456789e-5);  	|1.235e-05|
printf("|%.4g|\n",1.234567890123456789e5);   	|1.235e+05|
printf("|%.4g|\n",1.234567890123456789e-3);  	|0.001235|
printf("|%.8g|\n",1.234567890123456789e5);   	|123456.79|



Matthieu Moy 2017-02-08