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
+4.3k Nginx : Password protect a directory/folder
+8.8k Golang : Encrypt and decrypt data with x509 crypto
+4k Golang : Get missing location after unmarshal binary and gob decode time.
+3.9k Golang : Shuffle array of list
+14.9k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+3.1k Python : Convert(cast) bytes to string example
+6.4k Golang : Read file with ioutil
+9k Golang : Pass database connection to function called from another package and HTTP Handler
+17.5k Golang : How to run Golang application such as web server in the background or as daemon?
+3.4k Golang : Return multiple values from function
+2.1k Golang : Trim everything onward after a word