Go · lesson 4 of 30 · First stepsCount with numbers
Division of whole numbers drops the fraction; float64(x) keeps it. A const is a fixed value.
04-numbers.go Download 04-numbers.go
package main
import (
"fmt"
"math"
)
const gib = 1 << 30
func main() {
fmt.Println("17 / 5 =", 17/5) // whole numbers give a whole number
fmt.Println("17 % 5 =", 17%5)
fmt.Println("17.0 / 5 =", 17.0/5)
var bytes int64 = 8001563222016
fmt.Printf("%.1f GiB\n", float64(bytes)/gib)
size := 3.7
fmt.Println("rounded:", math.Round(size), "cut:", int(size))
fmt.Println("largest int64:", int64(math.MaxInt64))
}
Terminal
$ ./04-numbers
17 / 5 = 3
17 % 5 = 2
17.0 / 5 = 3.4
7452.0 GiB
rounded: 4 cut: 3
largest int64: 9223372036854775807Exercise
Turn 500 GB into GiB.
TurboShell does not contain Go. These programs are made in Bucket & Code with its Go runtime; the finished file runs on the NAS without Go.