![](/img/trans.png)
[英]How to convert negative numbers and numbers with decimal point , in binary, hexadecimal, octal, decimal
[英]How we can write binary, octal and hexadecimal literals of floating point numbers in Java?
我們如何在 Java 中編寫浮點數的二進制、八進制和十六進制文字? 無論是在科學上還是在正常表示中。
class First
{
public static void main(String[] args)
{
double b = 0x12p3;
System.out.println(b);
}
}
以上程序結果 144.0
class First
{
public static void main(String[] args)
{
double b = 0x12e3;
System.out.println(b);
}
}
以上程序結果4835.0
class First
{
public static void main(String[] args)
{
double b = 0x12e3;
System.out.println(b);
}
}
以上程序結果4835.0
class First
{
public static void main(String[] args)
{
double b = 012e3;
System.out.println(b);
}
}
以上程序結果 12000
請解釋以上輸出。
第一個例子是一個 HexadecimalFloatingPointLiteral,(16+2)*8 = 144。
第二個和第三個例子實際上是一個 HexIntegerLiteral 分配給一個 double 變量,1*16*16*16 + 2*16*16 + 14*16 + 3 = 4835。請注意,'e' 只是 14 的十六進制數字.
最后一個例子是一個 DecimalFloatingPointLiteral,12 * 1000。
Java 不支持八進制浮點文字。
有關所有詳細信息,請參閱 JLS: https : //docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.