Java 浮点数转换字符
浮点数转换符有以下几种。
| 字符 | 说明 |
|---|---|
| %e | 以计算机科学指数表示法表示的小数 |
| %E | 以计算机科学指数表示法表示的小数 |
| %f | 小数 |
| %g | 根据计算机科学指数表示法或十进制格式, |
| %G | 根据计算机科学指数表示法或十进制格式, |
示例
public class Demo {
public static void main(String[] args) throws Exception {
System.out.printf("Integer conversions...
");
System.out.printf( "Integer: %d
", 889 );
System.out.printf( "Negative Integer: %d
", -78 );
System.out.printf( "Octal: %o
", 677 );
System.out.printf( "Hexadecimal: %x
", 56 );
System.out.printf( "Hexadecimal: %X
", 99 );
System.out.printf("
Floating-point conversions...
");
System.out.printf( "%e
", 29567457.78 );
System.out.printf( "%E
", 34567457.89 );
System.out.printf( "%f
", 69874789.11 );
System.out.printf( "%g
", 7567579.38 );
System.out.printf( "%G
", 4766757.67 );
}
}输出
Integer conversions... Integer: 889 Negative Integer: -78 Octal: 1245 Hexadecimal: 38 Hexadecimal: 63 Floating-point conversions... 2.956746e+07 3.456746E+07 69874789.110000 7.56758e+06 4.76676E+06
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP