Skip to content

Commit

Permalink
Improve float formatting in CSV output (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored May 15, 2024
1 parent e83fbcf commit ccf4255
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [[v0.8.1]](https://github.com/mlange-42/arche-model/compare/v0.8.0...v0.8.1)

### Other

* Improved float formatting in CSV output (#64)

## [[v0.8.0]](https://github.com/mlange-42/arche-model/compare/v0.7.0...0.8.0)

### Features
Expand Down
3 changes: 2 additions & 1 deletion reporter/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/mlange-42/arche-model/observer"
Expand Down Expand Up @@ -60,7 +61,7 @@ func (s *CSV) Update(w *ecs.World) {
s.builder.Reset()
fmt.Fprintf(&s.builder, "%d%s", s.step, s.Sep)
for i, v := range values {
fmt.Fprintf(&s.builder, "%f", v)
fmt.Fprint(&s.builder, strconv.FormatFloat(v, 'f', -1, 64))
if i < len(values)-1 {
fmt.Fprint(&s.builder, s.Sep)
}
Expand Down
3 changes: 2 additions & 1 deletion reporter/csv_snaphot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/mlange-42/arche-model/observer"
Expand Down Expand Up @@ -67,7 +68,7 @@ func (s *SnapshotCSV) Update(w *ecs.World) {
s.builder.Reset()
for _, row := range values {
for i, v := range row {
fmt.Fprintf(&s.builder, "%f", v)
fmt.Fprint(&s.builder, strconv.FormatFloat(v, 'f', -1, 64))
if i < len(row)-1 {
fmt.Fprint(&s.builder, s.Sep)
}
Expand Down

0 comments on commit ccf4255

Please sign in to comment.