Created
July 24, 2013 20:35
-
-
Save chespinoza/6074284 to your computer and use it in GitHub Desktop.
i/o to float parsing test with go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"bytes" | |
"fmt" | |
"strconv" | |
"strings" | |
) | |
func Strcat(str ...string) string { | |
var buffer bytes.Buffer | |
for _, val := range str { | |
buffer.WriteString(val) | |
} | |
return buffer.String() | |
} | |
func main() { | |
str := []byte("C=34041\r\n") | |
reader := bufio.NewReader(strings.NewReader(string(str))) | |
line, _ := reader.ReadString('\n') | |
if line[:1] == "C" { | |
myf := Strcat(line[2:5], ".", line[5:]) | |
f, err := strconv.ParseFloat(strings.TrimSpace(myf), 64) | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Println(f) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment