MCPcopy Index your code
hub / github.com/coder/coder / toMicros

Function toMicros

scripts/aibridgepricesgen/main.go:190–200  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

188// rounding to avoid float-truncation errors. Returns nil for nil input, and
189// for negative values, which are treated as missing.
190func 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 &micros
200}
201
202func write(w io.Writer, rows []priceRow) error {
203 enc := json.NewEncoder(w)

Callers 2

TestToMicrosFunction · 0.85
convertFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestToMicrosFunction · 0.68