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
+12.1k Golang : Check if a file exist or not
+5.3k Golang : Example of custom handler for Gorilla's Path usage.
+4.4k Facebook : How to force facebook to scrape latest URL link data?
+5.8k Golang : How to convert strange string to JSON with json.MarshalIndent
+3.2k MariaDB/MySQL : How to get version information
+4.6k Golang : Handling image beyond OpenCV video capture boundary
+11.7k Golang : Check if an integer is negative or positive
+16.3k Golang : Compare floating-point numbers
+4.3k PHP : Proper way to get UTF-8 character or string length
+9.7k Golang : Gorilla web tool kit secure cookie example
+32k Golang : convert(cast) bytes to string