pointers
This commit is contained in:
30
bank/fileops/fileops.go
Normal file
30
bank/fileops/fileops.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user