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
+21.2k Golang : Encrypt and decrypt data with TripleDES
+7.5k Golang : Lock executable to a specific machine with unique hash of the machine
+11.4k Golang : Surveillance with web camera and OpenCV
+7k Golang : Check if one string(rune) is permutation of another string(rune)
+4.5k JavaScript: Add marker function on Google Map
+6.1k Golang : Test input string for unicode example
+6.1k Golang : Extract sub-strings
+10.6k PHP : Convert(cast) bigInt to string
+11.9k Golang : md5 hash of a string
+14.8k JavaScript/JQuery : Detect or intercept enter key pressed example
+27.3k PHP : Count number of JSON items/objects
+16.8k Golang : XML to JSON example