Commit a8d4746d by huangchengyi

1.0

parent caaf69a1
Showing with 27 additions and 0 deletions
package main
import (
"fmt"
"strconv"
)
func main() {
var a,b,c float64
a=1.69*100
b=1.7*10
c=a*b/(100*10)
//正确结果2.873
fmt.Println(c)
//fmt.Println(fmt.Sprintf("%.2f",c))
//fmt.Println(FloatRound(c,2))
}
// 截取小数位数
func FloatRound(f float64, n int) float64 {
format := "%." + strconv.Itoa(n) + "f"
//fmt.Println(format)
res, _ := strconv.ParseFloat(fmt.Sprintf(format, f), 64)
return res
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment