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.8k Chrome : How to block socketloop.com links in Google SERP?
+8.8k Golang : Combine slices but preserve order example
+15.9k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+7.6k Golang : Check to see if *File is a file or directory
+6.3k Golang : Grab news article text and use NLP to get each paragraph's sentences
+10.8k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+21.5k Golang : How to force compile or remove object files first before rebuild?
+30.8k Golang : Remove characters from string example
+8.3k Android Studio : Rating bar example
+5.5k Golang : Intercept, inject and replay HTTP traffics from web server
+7k Android Studio : Hello World example
+17.2k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error