嗨,我是新來的編程語言。學習去 - 範圍
學習在第四章中,在練習中,對從轉換到華氏攝氏度的問題。
我編寫了答案如下
package main
import "fmt"
func main(){
fmt.Println("Enter temperature in Farentheit ");
var input float64
fmt.Scanf("%f",&input)
var outpu1 float64 = (((input-32)* (5)) /9)
var outpu2 float64= (input-32) * (5/9)
var outpu3 float64= (input -32) * 5/9
var outpu4 float64= ((input-32) * (5/9))
fmt.Println("the temperature in Centigrade is ",outpu1)
fmt.Println("the temperature in Centigrade is ",outpu2)
fmt.Println("the temperature in Centigrade is ",outpu3)
fmt.Println("the temperature in Centigrade is ",outpu4)
}
輸出結果如下
sreeprasad:projectsInGo sreeprasad$ go run convertFarentheitToCentigrade.go
Enter temperature in Farentheit
12.234234
the temperature in Centigrade is -10.980981111111111
the temperature in Centigrade is -0
the temperature in Centigrade is -10.980981111111111
the temperature in Centigrade is -0
我的問題是與outpu2和outpu4。括號是正確的,但是如何或爲什麼打印-0。
任何人都可以請解釋
是的,標準化的浮點數有+0,-0,NaN,+ Infinity和-Infinity的特殊表示。你不能保留一些整數的組合來具有這樣的含義...... – PhiLho
+1用於回答對問題的其他解釋。我甚至沒有注意到負號:) – dskinner
@dskinner謝謝!負面信號引起了我的注意,因爲我也不知道原因。所以我做了一些研究:) –