succd: log pressures in error messages

This commit is contained in:
Serge Bazanski 2024-09-28 09:46:18 +02:00
parent 451b44e31b
commit 590e93e43e
3 changed files with 31 additions and 25 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"fmt"
"html/template"
"strconv"
)
@ -16,8 +17,25 @@ func (s *ScientificNotationValue) UnmarshalText(text []byte) error {
return nil
}
func (s *ScientificNotationValue) MarshalText() ([]byte, error) {
v := float64(*s)
// formatMbarHTML formats a millibar value using scientific notation and returns
// a HTML fragment (for superscript support).
func formatMbarHTML(v float32) template.HTML {
exp := 0
for v < 1 {
v *= 10
exp -= 1
}
for v >= 10 {
v /= 10
exp += 1
}
res := fmt.Sprintf("%.3f", v)
res += fmt.Sprintf(" x 10<sup>%d</sup>", exp)
res += " mbar"
return template.HTML(res)
}
func formatMbar(v float32) string {
exp := 0
for v < 1 {
v *= 10
@ -29,5 +47,11 @@ func (s *ScientificNotationValue) MarshalText() ([]byte, error) {
}
res := fmt.Sprintf("%.3f", v)
res += fmt.Sprintf("e%d", exp)
return res
}
func (s *ScientificNotationValue) MarshalText() ([]byte, error) {
v := float32(*s)
res := formatMbar(v)
return []byte(res), nil
}