Skip to content

Commit c84f2dc

Browse files
committed
ability to remove scientific notation
1 parent 6cf9c4c commit c84f2dc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

commands.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56
)
67

@@ -30,6 +31,8 @@ func tryCommands(line string, stack *Stack, operators OperatorMap) error {
3031
}
3132
case "sort":
3233
stack.Sort()
34+
case "f":
35+
fmt.Println(stack.StringF())
3336
case "cl":
3437
fallthrough
3538
case "clr":

stack.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ func (s *Stack) Empty() bool {
7171
return s.Len() <= 0
7272
}
7373

74-
func (s *Stack) String() string {
74+
func (s *Stack) StringImpl(verb string) string {
7575
stackSize := s.Len()
7676
var b strings.Builder
7777
fmt.Fprintf(&b, "[ ")
7878
for i, n := range s.storage {
79-
fmt.Fprintf(&b, "%g", n)
79+
fmt.Fprintf(&b, verb, n)
8080
if i < stackSize-1 {
8181
fmt.Fprintf(&b, " ")
8282
}
@@ -85,6 +85,14 @@ func (s *Stack) String() string {
8585
return b.String()
8686
}
8787

88+
func (s *Stack) String() string {
89+
return s.StringImpl("%g")
90+
}
91+
92+
func (s *Stack) StringF() string {
93+
return s.StringImpl("%f")
94+
}
95+
8896
func (s *Stack) Sort() {
8997
slices.Sort(s.storage)
9098
}

0 commit comments

Comments
 (0)