Go Remainder()

regantewksbury's avatar
Published Sep 16, 2023
Contribute to Docs

The Remainder() function returns the remainder of the division of two given values. The remainder may be a whole or a floating-point number.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn how to use Go (Golang), an open-source programming language supported by Google!
    • Beginner Friendly.
      6 hours

Syntax

result := math.Remainder(num1, num2)

math.Remainder() returns the whole or IEEE 754 floating-point remainder of num1 divided by num2, except in four special cases:

  • If num1 equals +-Inf the function will return NaN.
  • If num2 equals +-Inf the function returns num1.
  • If either argument is NaN the function will return NaN.
  • If num2 equals 0 the function will return NaN.

Example

This example divides two integer values and returns the remainder result.

package main
import (
"fmt"
"math"
)
func main() {
result := math.Remainder(2, 35)
fmt.Printf("%.1f\n", result)
}

This will return:

2.0

Codebyte Example

The following example can be run and uses the math.Remainder() function to return the remainder of two given values. The second call is an example of a special case and returns NaN.

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Go on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn how to use Go (Golang), an open-source programming language supported by Google!
    • Beginner Friendly.
      6 hours