toMicros scales a price into integer micro-units (1 unit = 1,000,000), rounding to avoid float-truncation errors. Returns nil for nil input, and for negative values, which are treated as missing.
(price *float64)
| 188 | // rounding to avoid float-truncation errors. Returns nil for nil input, and |
| 189 | // for negative values, which are treated as missing. |
| 190 | func toMicros(price *float64) *int64 { |
| 191 | if price == nil { |
| 192 | return nil |
| 193 | } |
| 194 | if *price < 0 { |
| 195 | _, _ = fmt.Fprintf(os.Stderr, "warning: negative price %f, treating as missing\n", *price) |
| 196 | return nil |
| 197 | } |
| 198 | micros := int64(math.Round(*price * 1_000_000)) |
| 199 | return µs |
| 200 | } |
| 201 | |
| 202 | func write(w io.Writer, rows []priceRow) error { |
| 203 | enc := json.NewEncoder(w) |
no outgoing calls