This commit is contained in:
2024-10-20 21:07:51 +00:00
parent ac623d6d49
commit ed60288a2a
8 changed files with 82 additions and 32 deletions

30
bank/fileops/fileops.go Normal file
View File

@@ -0,0 +1,30 @@
package fileops
import (
"errors"
"fmt"
"os"
"strconv"
)
func GetFloatFromFile(fileName string) (float64, error) {
data, err := os.ReadFile(fileName)
if err != nil {
return 1000, errors.New("Failed to find file.")
}
valueText := string(data)
value, err :=strconv.ParseFloat(valueText, 64)
if err != nil {
return 1000, errors.New("Failed to parse stored value.")
}
return value, nil
}
func WriteFloatToFile(value float64, fileName string) {
valueText := fmt.Sprint(value)
os.WriteFile(fileName, []byte(valueText), 0644)
}