Last active
January 9, 2022 13:27
-
-
Save percybolmer/8ca03112d5a713249d9c7d513923960c to your computer and use it in GitHub Desktop.
go.1.18 subtract regular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main(){ | |
var a int = 20 | |
var b int = 10 | |
var c float32 = 20 | |
var d float32 = 10.5 | |
result := Subtract(a, b) | |
// We need to cast data type into int here | |
resultfloat := Subtract(int(c), int(d)) | |
// Will return 10 | |
fmt.Println("Result:", result) | |
// Will return 10 -- Which is wrong, we should get 9.5 but we need a extra function for that to work | |
fmt.Println("Resultfloat:", resultfloat) | |
} | |
// Subtract will subtract the second value from the first | |
func Subtract(a, b int) int { | |
return a - b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment