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 : Find and draw contours with OpenCV example
+6.4k Golang : How to search a list of records or data structures
+6.3k Golang : Calculate US Dollar Index (DXY)
+3.4k Golang : Fix go-cron set time not working issue
+26.8k Golang : Convert file content into array of bytes
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+10.9k Golang : Command line file upload program to server example
+30.1k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+43.6k Golang : Get hardware information such as disk, memory and CPU usage
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+15.9k Golang : Read a file line by line
+8.9k Golang : Find network service name from given port and protocol