Compare commits

...

1 Commits

Author SHA1 Message Date
Srikanth Chekuri
6b065aa54c fix(querybuildertypesv5): guard float overflow in roundToNonZeroDecimals (#12151)
Some checks are pending
build-staging / prepare (push) Waiting to run
build-staging / js-build (push) Blocked by required conditions
build-staging / go-build (push) Blocked by required conditions
build-staging / staging (push) Blocked by required conditions
Release Drafter / update_release_draft (push) Waiting to run
math.Round(val*multiplier)/multiplier overflows to +Inf for finite values
near math.MaxFloat64, turning a valid series value into JSON-unmarshalable
Inf downstream. Return the value unrounded when the scaled intermediate
overflows.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 08:48:33 +00:00

View File

@@ -328,6 +328,11 @@ func roundToNonZeroDecimals(val float64, n int) float64 {
// Round to n decimal places
multiplier := math.Pow(10, float64(n))
rounded := math.Round(val*multiplier) / multiplier
if math.IsInf(rounded, 0) {
// val*multiplier overflowed for near-max float64 values; the
// finite input must stay finite or the JSON encoder rejects it.
return val
}
// If the result is a whole number, return it as such
if rounded == math.Trunc(rounded) {