Russ Cox | e219555 | 2021-11-18 12:03:46 -0500 | [diff] [blame] | 1 | // +build ignore,OMIT |
2 | |||||
3 | package main | ||||
4 | |||||
5 | import "fmt" | ||||
6 | |||||
7 | type Celsius float32 | ||||
8 | type Fahrenheit float32 | ||||
9 | |||||
10 | func (t Celsius) String() string { return fmt.Sprintf("%g°C", t) } | ||||
11 | func (t Fahrenheit) String() string { return fmt.Sprintf("%g°F", t) } | ||||
12 | func (t Celsius) ToFahrenheit() Fahrenheit { return Fahrenheit(t*9/5 + 32) } | ||||
13 | |||||
14 | func main() { | ||||
15 | var t Celsius = 21 | ||||
16 | fmt.Println(t.String()) | ||||
17 | fmt.Println(t) | ||||
18 | fmt.Println(t.ToFahrenheit()) | ||||
19 | } |