Go Max()

manikanta528's avatar
Published Jun 28, 2023

The Max() function returns the maximum value of two specified numbers.

  • 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

import "math"

result := math.Max(num1, num2)

math.Max() returns the maximum value from num1 and num2.

Example

The following example compares two integer values and prints out the maximum value result.

package main
import (
"fmt"
"math"
)
func main() {
result := math.Max(27, 28)
fmt.Printf("%.1f\n", result)
}

The output will be:

28.0

Codebyte Example

The following example is runnable and uses the math.Max() method to return the maximum value from the two given numbers.

Code
Output

All contributors

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