使用包tempconv进行摄氏与华氏温度的转换

5年以前  |  阅读数:666 次  |  编程语言:Golang 

使用包tempconv进行摄氏与华氏温度的转换。

//Cf converts its numeric argument to Celsius and Fahrenheit.

package main

import (
    "fmt"
    "os"
    "strconv"

    "gopl.io/ch2/tempconv"
)

func main() {
    for _, arg := range os.Args[1:] {
        t, err := strconv.ParseFloat(arg, 64)
        if err != nil {
            fmt.Fprintf(os.Stderr, "cf: %v\n", err)
            os.Exit(1)
        }
        f := tempconv.Fahrenheit(t)
        c := tempconv.Celsius(t)
        fmt.Printf("%s = %s, %s = %s\n",
            f, tempconv.FToC(f), c, tempconv.CToF(c))
    }
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8