Skip to content

Commit

Permalink
Limit alert value to 4 decimal places when displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolas committed May 9, 2020
1 parent dd8f18a commit 877554b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions alertscollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"math"
"net"
"time"

Expand Down Expand Up @@ -142,10 +143,17 @@ func (ac *alertsCollection) DisplayAll() {
}
}

func roundToFourPlaces(n float64) float64 {
return math.Round(n * 10000) / 10000
}

func (ac *alertsCollection) MakePageResponse() pageResponse {
pr := pageResponse{GraphiteBase: graphiteBase,
MetricBase: metricBase}
for _, a := range ac.alerts {
// Format floats to four decimal places for display.
a.Value = roundToFourPlaces(a.Value)

pr.Alerts = append(pr.Alerts, a)
}
return pr
Expand Down

0 comments on commit 877554b

Please sign in to comment.