GO語言"math"包中"Modf"函數的用法及代碼示例。
用法:
func Modf(f float64)(int float64, frac float64)
Modf 返回總和為 f 的整數和小數浮點數。這兩個值與 f 具有相同的符號。
特殊情況是:
Modf(±Inf) = ±Inf, NaN Modf(NaN) = NaN, NaN
例子:
package main
import (
"fmt"
"math"
)
func main() {
int, frac := math.Modf(3.14)
fmt.Printf("%.2f, %.2f\n", int, frac)
int, frac = math.Modf(-2.71)
fmt.Printf("%.2f, %.2f\n", int, frac)
}
輸出:
3.00, 0.14 -2.00, -0.71
相關用法
- GO Mod用法及代碼示例
- GO Month用法及代碼示例
- GO MethodSet用法及代碼示例
- GO MakeFunc用法及代碼示例
- GO Mul32用法及代碼示例
- GO Mkdir用法及代碼示例
- GO Map用法及代碼示例
- GO MkdirTemp用法及代碼示例
- GO MakeTable用法及代碼示例
- GO Mul64用法及代碼示例
- GO MultiReader用法及代碼示例
- GO MultiWriter用法及代碼示例
- GO MarshalIndent用法及代碼示例
- GO Marshal用法及代碼示例
- GO MatchString用法及代碼示例
- GO Match用法及代碼示例
- GO MkdirAll用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO LeadingZeros32用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Modf。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。