求取概率

package main

import (
   "fmt"
   "strconv"
)

// 求取概率
func main() {
   // 分子为n,分母为m
   m, n := 125, 3
   // 把分子,分母转换为浮点数
   m1, n1 := float32(m), float32(n)
   // 求取结果保留两位小数
   res := fmt.Sprintf("%.2f", m1/n1)
   s, _ := strconv.ParseFloat(res, 32)

   fmt.Println(res)
   fmt.Printf("%T\n", res)
   fmt.Println(s)
   fmt.Printf("%T", s)

   w := m1 / n1
   fmt.Println(w)
   fmt.Printf("%T", w)

}

猜你喜欢

转载自blog.csdn.net/q320036715/article/details/84898979