celsius.go 292 B

1234567891011121314151617181920
  1. // celsius.go
  2. package main
  3. import (
  4. "fmt"
  5. "strconv"
  6. )
  7. type Celsius float64
  8. func (c Celsius) String() string {
  9. return "The temperature is: " + strconv.FormatFloat(float64(c), 'f', 1, 32) + " °C"
  10. }
  11. func main() {
  12. var c Celsius = 18.36
  13. fmt.Println(c)
  14. }
  15. // The temperature is: 18.4 °C