Go Min()
Published Jun 30, 2023
The Min() function returns the minimum value of two specified numbers.
Syntax
import "math"
result := math.Min(num1, num2)
math.Min() returns the minimum value from num1 and num2.
Example
The following example compares two integer values and prints out the minimum value result.
package mainimport ("fmt""math")func main() {result := math.Min(6, 11)fmt.Printf("%.1f\n", result)}
The output will be:
6.0
Codebyte Example
The following example is runnable and uses the math.Min() method to return the minimum value from the two given numbers.
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