Abs in Go

Posted by GoDoc
Public (Editable by Users)

Abs returns the absolute value of x.

Go
Edit
package main

import (
	"fmt"
	"math"
)

func main() {
	x := math.Abs(-2)
	fmt.Printf("%.1f\n", x)

	y := math.Abs(2)
	fmt.Printf("%.1f\n", y)
}