Golang : Check if an integer is negative or positive
A simple example on how to check if a given number is negative or positive number in Golang.
Here you go!
package main
import (
"fmt"
"math"
)
func main() {
integer := -1.0
fmt.Println("Integer is negative number :", math.Signbit(integer))
integer2 := 1.0
fmt.Println("Integer2 is negative number : ", math.Signbit(integer2))
}
Output:
Integer is negative number : true
Integer2 is negative number : false
See also : Golang : Count number of digits from given integer value
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+18.3k Golang : Determine if directory is empty with os.File.Readdir() function
+8.3k Golang : Changing a RGBA image number of channels with OpenCV
+15.2k Golang : Convert slice to array
+17.3k Golang : Check whether a network interface is up on your machine
+37.6k Golang : How to read CSV file
+9.8k Golang : How to determine a prime number?
+6k Golang : Get Alexa ranking data example
+16.1k Golang : Find smallest number in array
+5.2k Golang : Experimental emojis or emoticons icons programming language
+18.3k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+16.3k Golang : [json: cannot unmarshal object into Go value of type]
+9.6k Golang : Get currencies exchange rates example