Commit f9f8cb8167

f9f8cb81671915b6b187d1c7f3cb48056b6390a3

parent: 2893c158e9

Verified · cmc

cmc <hello@cleberg.net> · 2026-09-26 19:17 UTC

Round aperture to two significant figures

exiftool -n reports the raw FNumber (1.779999971), which was printed
verbatim as f/1.779999971.

Layout: unified · split

internal/format/exif.go +3 −1
@@ -47,7 +47,9 @@ func parseExif(data []byte) (Meta, error) {
47 } 47 }
48 m.Camera = camera(e.Make, e.Model) 48 m.Camera = camera(e.Make, e.Model)
49 if e.FNumber > 0 { 49 if e.FNumber > 0 {
50 m.Aperture = "f/" + strconv.FormatFloat(e.FNumber, 'f', -1, 64) 50 // Two significant figures, as f-numbers are written (0.95, 1.8, 5.6, 22);
51 // exiftool -n reports the raw value, e.g. 1.779999971.
52 m.Aperture = "f/" + strconv.FormatFloat(e.FNumber, 'g', 2, 64)
51 } 53 }
52 m.Shutter = shutter(e.ExposureTime) 54 m.Shutter = shutter(e.ExposureTime)
53 return m, nil 55 return m, nil
internal/format/exif_test.go +12
@@ -81,3 +81,15 @@ func TestParseExifErrors(t *testing.T) {
81 } 81 }
82 } 82 }
83} 83}
84
85func TestParseExifRoundsAperture(t *testing.T) {
86 for in, want := range map[string]string{"1.779999971": "f/1.8", "2": "f/2", "5.6": "f/5.6", "11": "f/11", "22": "f/22", "0.95": "f/0.95"} {
87 m, err := parseExif([]byte(`[{"ImageWidth": 1, "ImageHeight": 1, "FNumber": ` + in + `}]`))
88 if err != nil {
89 t.Fatal(err)
90 }
91 if m.Aperture != want {
92 t.Errorf("FNumber %s: got %q, want %q", in, m.Aperture, want)
93 }
94 }
95}