Golang
Get absolute value
in Golang
Get absolute value of argument. Use Abs() of math package for both of integer and float.
get_absolute_value.go
package main import ( "fmt" "math" ) func main() { // Get absolute value of integer fmt.Println("Absolute value of 5 is ", math.Abs(5)) fmt.Println("Absolute value of -5 is ", math.Abs(-5)) // Get absolute value of float fmt.Println("Absolute value of 5.5 is ", math.Abs(5.5)) fmt.Println("Absolute value of -5.5 is ", math.Abs(-5.5)) }
Result
$ go run get_absolute_value.go Absolute value of 5 is 5 Absolute value of -5 is 5 Absolute value of 5.5 is 5.5 Absolute value of -5.5 is 5.5