Added support for rounding of values by default in API responses
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful

This commit is contained in:
2026-03-20 11:30:11 -05:00
parent bb18bcfb15
commit 6806de3c0a
10 changed files with 369 additions and 68 deletions

View File

@@ -2,7 +2,10 @@
// Layer: adapters/inbound/httpapi/presenter helper functions.
package presenter
import "time"
import (
"math"
"time"
)
func celsiusToFahrenheitPtr(v *float64) *float64 {
if v == nil {
@@ -53,3 +56,19 @@ func boolText(v *bool) string {
}
return "false"
}
func roundedPtr(v *float64, precision int) *float64 {
if v == nil {
return nil
}
out := roundFloat(*v, precision)
return &out
}
func roundFloat(v float64, precision int) float64 {
if precision <= 0 {
return math.Round(v)
}
factor := math.Pow10(precision)
return math.Round(v*factor) / factor
}