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
+17.2k Golang : Read binary file into memory
+7.1k Golang : Emulate NumPy way of creating matrix example
+3.9k Golang : Customize scanner.Scanner to treat dash as part of identifier
+26.6k Golang : Change a file last modified date and time
+40.5k Golang : Convert []byte to image
+8.1k Golang : Timeout example
+15.6k Golang : Get input from keyboard
+4.2k PHP : See installed compiled-in-modules
+46.9k Golang : Upload file from web browser to server
+9.1k Golang : Get login name from environment and prompt for password
+33.7k Golang : Strip slashes from string example
+14.9k Golang : Find out mime type from bytes in buffer