System.out.printf('%h', float f )
/**
* Output:
sci not num is 3.141593e+04
sci not num is 31415.9
sci not num is 1.234568e-01
sci not num is 0.123457
sci not num is 3.000000e+06
hex num is 3ff00000
num is cafe
*/
public class MainClass {
public static void main(String args[]) throws Exception {
System.out.printf("sci not num is %e\n", 3.14159265*10000 );
System.out.printf("sci not num is %g\n", 3.14159265*10000 );
System.out.printf("sci not num is %e\n", 0.123456789 );
System.out.printf("sci not num is %g\n", 0.123456789 );
System.out.printf("sci not num is %e\n", 3000000.0 );
System.out.printf("hex num is %h\n", 1.0 );
System.out.printf("num is %h\n", 0xCAFE );
}
}
Related examples in the same category
1. | System.out.printf('%b', String str ) | | |
2. | System.out.printf('%c', char ch ) | | |
3. | System.out.printf('%03d', int i ) | | |
4. | System.out.printf('%e', float ) | | |
5. | System.out.printf('%03f', float f) | | |
6. | System.out.printf('%.2f', float f ) | | |
7. | System.out.printf('{%07.3f}', float f ) | | |
8. | System.out.printf('%f', float f ) | | |
9. | System.out.printf('%g', float f ) | | |
10. | System.out.printf('%s', 5) | | |
11. | System.out.printf('%s://%s/%s\n', String str1, String str2, String str3) | | |
12. | System.out.printf('%1 s...', String str ) | | |
13. | System.out.printf('%5s', String str) | | |
14. | System.out.printf('%-5s', String str) (2) | | |
15. | System.out.printf( '%-10.10s %s', String word, int length ) | | |
16. | System.out.printf('%.5s', String str) (3) | | |
17. | System.out.printf('%s', Date date ) | | |
18. | System.out.printf('%tc', Date date ) (lowercase t, lowercase c) | | |
19. | System.out.printf('%tC', Date date ) (lowercase t, uppercase C) | | |
20. | System.out.printf('%tD', Date date ) | | |
21. | System.out.printf('%tF', Date date ) | | |
22. | System.out.printf('%tr', Date date ) | | |
23. | System.out.printf('%tR',Date date ) | | |
24. | System.out.printf('%tT', Date date ) | | |
25. | System.out.printf('%tz', Date date ) | | |
26. | System.out.printf('%Tc', Date date ) (Uppercase T, lowercase c) | | |
27. | System.out.printf('%1x, %1X', 0xCAFE ) | | |
28. | System.out.printf( Locale.CHINA, '%tc', Date date ) | | |
29. | System.out.printf( Locale.ITALIAN, '%tc', Date date ) | | |