Standard library / math

math.Modf()

Splits a float into integer and fractional parts, both with the input sign. Expected stdout: '-2 -0.5\n'.

Formal Syntax & Structure

go syntaxgo
func Modf(f float64) (int float64, frac float64)

Parameters & Attributes

NameTypeDescription
ffloat64Input floating-point value.

Return Value

(int float64, frac float64)

Splits a float into integer and fractional parts, both with the input sign.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math")
func main() {  i, f := math.Modf(-2.5)  fmt.Println(i, f)}
Go Reference