Created
August 10, 2019 20:35
-
-
Save vlad-bezden/79f05513e8a2899a56e23692920f159d to your computer and use it in GitHub Desktop.
To minimize rounding errors, perform multiplication before division. The result tends to be more accurate that way.
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
package main | |
import "fmt" | |
func main() { | |
fmt.Println("1. Division First") | |
celsius := 21.0 | |
fmt.Print((celsius/5.0*9.0)+32, "° F\n") | |
fmt.Print((9.0/5.0*celsius)+32, "° F\n\n") | |
fmt.Println("2. Multiplication First") | |
fahrenheit := (celsius * 9.0 / 5.0) + 32.0 | |
fmt.Print(fahrenheit, "° F") | |
} | |
/* | |
OUTPUT | |
1. Division First | |
69.80000000000001° F | |
69.80000000000001° F | |
2. Multiplication First | |
69.8° F | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment