Modf()
Anonymous contributor
Anonymous contributor1 total contribution
Anonymous contributor
Published Aug 1, 2023
Contribute to Docs
The Modf()
function in Go is used to find the integer and fractional part of a floating-point number. This function is part of the math
package, and the package must be imported to use the function in a Go program.
Syntax
int, frac := Modf(f)
Where:
f
: is the floating-point number to extract the integer and fractional parts from.int
: is the integer part of the passed parameter.frac
: is the fractional part of the passed parameter.
Some special return cases:
- If (±)Inf is passed as an argument, then
Modf
returns (±)Inf andNAN
. - If the argument passed is
NAN
, then the return will also beNAN
.
Example
Below is a basic implementation of the Modf()
function.
package mainimport("fmt""math")func main() {var x float64 = 3.3456var w, z float64 = math.Modf(x)fmt.Print("The value ", x, " is composed of the integer: ", w, " and the fractional part: ", z)}
The output will be:
The value 3.3456 is composed of the integer: 3 and the fractional part: 0.34560000000000013
Codebyte Example
The following example shows how the Modf()
function can be used in a Go program:
All contributors
- Anonymous contributorAnonymous contributor1 total contribution
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.