为什么 unicode.IsNumber(rune(truncfloat)) 在某些情况下返回 false?
55.3 输出为真 58.3 输出为假
下面是我的代码:
package main
import (
"fmt"
"unicode"
)
func main() {
var truncint int
var truncfloat float64
fmt.Printf("Enter a floating point number: ")
num, err := fmt.Scan(&truncfloat)
if unicode.IsNumber(rune(truncfloat)) {
truncint = int(truncfloat)
fmt.Printf("Trucated number is: %d", truncint)
} else {
fmt.Printf("Recieved %d numbers, Error: %s", num, err)
}
}
以下是带有执行输出的测试用例:
PS C:\learngo> .\trunc.exe
Enter a floating point number: 58.3
Recieved 1 numbers, Error: %!s(<nil>)
PS C:\learngo> .\trunc.exe
Enter a floating point number: 55.3
Trucated number is: 55