package main
import (
"fmt"
"strings"
)
func main() {
givenDurationString := "5h37m34.574050332s"
keepNum := 1 //规划保留的小数点后位数
dotIndex := strings.IndexAny(givenDurationString, ".") //获取小数点所在的索引值
fmt.Println(givenDurationString[:dotIndex + keepNum + 1] + "s") //输出5h37m34.5s
}
网友评论