aboutsummaryrefslogtreecommitdiff
path: root/float64_slice.go
diff options
context:
space:
mode:
Diffstat (limited to 'float64_slice.go')
-rw-r--r--float64_slice.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/float64_slice.go b/float64_slice.go
index 45d12b8..85bf307 100644
--- a/float64_slice.go
+++ b/float64_slice.go
@@ -51,6 +51,44 @@ func (s *float64SliceValue) String() string {
return "[" + strings.Join(out, ",") + "]"
}
+func (s *float64SliceValue) fromString(val string) (float64, error) {
+ return strconv.ParseFloat(val, 64)
+}
+
+func (s *float64SliceValue) toString(val float64) string {
+ return fmt.Sprintf("%f", val)
+}
+
+func (s *float64SliceValue) Append(val string) error {
+ i, err := s.fromString(val)
+ if err != nil {
+ return err
+ }
+ *s.value = append(*s.value, i)
+ return nil
+}
+
+func (s *float64SliceValue) Replace(val []string) error {
+ out := make([]float64, len(val))
+ for i, d := range val {
+ var err error
+ out[i], err = s.fromString(d)
+ if err != nil {
+ return err
+ }
+ }
+ *s.value = out
+ return nil
+}
+
+func (s *float64SliceValue) GetSlice() []string {
+ out := make([]string, len(*s.value))
+ for i, d := range *s.value {
+ out[i] = s.toString(d)
+ }
+ return out
+}
+
func float64SliceConv(val string) (interface{}, error) {
val = strings.Trim(val, "[]")
// Empty string would cause a slice with one (empty) entry