douyu53265
2013-12-13 16:28
浏览 1.8k
已采纳

如何在Go中强制除法成为浮点数?

I have the following code snippet:

package main

import("fmt";"flag")

func main() {
    var a = flag.Int("a",0,"divident")
    var b = flag.Int("b",1,"divisor")
    flag.Parse()

    fmt.Printf("%f",*a / *b )
}

For -a 3 and -b 2 command line arguments, the output is: %!f(int=1)

What is the best / most elegant way to force this division to be floating point?

图片转代码服务由CSDN问答提供 功能建议

我有以下代码段:</ p>

  package main \  n 
import(“ fmt”;“ flag”)
 
func main(){
 var a = flag.Int(“ a”,0,“ divident”)
 var b = flag.Int(“ b  “,1,”除数“)
标志。Parse()
 
 fmt.Printf(”%f“,* a / * b)
} 
 </ code> </ pre> 
 \  n 

对于-a 3和-b 2命令行参数,输出为:%!f(int = 1)</ code> </ p>

什么是最好的 /强制该除法为浮点数的最优雅方法?</ p> </ div>

3条回答 默认 最新

相关推荐 更多相似问题