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
+10.2k Golang : Read file and convert content to string
+30.1k Golang : Record voice(audio) from microphone to .WAV file
+17.2k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+21.1k Golang : Underscore or snake_case to camel case example
+6.2k Golang : How to verify input is rune?
+11.5k Golang : How to use if, eq and print properly in html template
+12.6k Golang : Extract part of string with regular expression
+6.1k Facebook : How to force facebook to scrape latest URL link data?
+11.7k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+15.5k nginx: [emerg] unknown directive "ssl"
+9.4k Golang : Generate Codabar