Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Created August 10, 2019 20:51
Show Gist options
  • Save vlad-bezden/b908df125ed0ac2cb396e4b551b4b778 to your computer and use it in GitHub Desktop.
Save vlad-bezden/b908df125ed0ac2cb396e4b551b4b778 to your computer and use it in GitHub Desktop.
Rounding Errors example using addition in a loop versus multiplication
package main
import "fmt"
func main() {
piggyBank := 0.0
for i := 0; i < 11; i++ {
piggyBank += 0.1
}
fmt.Println("Using addition 11 times", piggyBank)
fmt.Println("Using multiplication", 0.1*11.0)
}
/*
OUTPUT
Using addition 11 times 1.0999999999999999
Using multiplication 1.1
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment