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
+11.3k Golang : Delay or limit HTTP requests example
+12.4k Golang : Forwarding a local port to a remote server example
+21.1k Golang : How to get time zone and load different time zone?
+16.5k Golang : Delete files by extension
+10.2k Golang : Convert file content to Hex
+20.1k Golang : Compare floating-point numbers
+27.5k PHP : Convert(cast) string to bigInt
+12.2k Golang : List running EC2 instances and descriptions
+12k Golang : Pagination with go-paginator configuration example
+10.8k Nginx : TLS 1.2 support
+29.5k Golang : Record voice(audio) from microphone to .WAV file