How to convert a float value to an absolute value in Go

1 Answer

0 votes
package main

import (
	"fmt"
)

func AbsFloat(x float64) float64 {
	if x < 0 {
		return -x
	}

	return x
}

func main() {
	fmt.Println(AbsFloat(-94872.89201))
}



/*
run:

94872.89201

*/

 



answered Aug 10, 2024 by avibootz
...