Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active January 9, 2022 13:27
Show Gist options
  • Save percybolmer/8ca03112d5a713249d9c7d513923960c to your computer and use it in GitHub Desktop.
Save percybolmer/8ca03112d5a713249d9c7d513923960c to your computer and use it in GitHub Desktop.
go.1.18 subtract regular
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