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
+8.8k Golang : Heap sort example
+7.1k Golang : Validate credit card example
+11.5k Golang : Concatenate (combine) buffer data example
+11k Golang : Get UDP client IP address and differentiate clients by port number
+5.5k Golang : Display advertisement images or strings on random order
+5.1k Golang : micron to centimeter example
+24.7k Golang : How to validate URL the right way
+34k Golang : Call a function after some delay(time.Sleep and Tick)
+11k Android Studio : Checkbox for user to select options example
+16.2k Golang : How to check if input from os.Args is integer?
+7.3k Golang : Of hash table and hash map
+20.1k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader