Added support for rounding of values by default in API responses
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user