string - How to Get Form Input as Float64 in Go -
I have a webform created using Go, when users enter a number, then I do some math on that number is required. It seems like all methods of using the HP package use string as the output.
How can I do simple math on user input?
Here I have the basic code:
func init () {http. HandleFunc ("/", root) http.HandleFunc ("/ results", result)} // root url handle func root (w http.ResponseWriter, r * http.Request) {fmt.Fprint (w, inputForm)} // root url html const input = `<& lt; Html & gt; & Lt; Body & gt; & Lt; Form action = "/ results" method = "post" & gt; & Lt; Div & gt; Number between 0 and 1 & lt; Input type = "text" name = "arrow" & gt; & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt; `Fink result (w http.ResponseWriter, r * http.Request) {input: = r.FormValue (" anar ") // Form-value is always string / add numbers to input: = input + 0.25 / output Output
Input first a float Convert < Flavale, err: = strconv.ParseFloat (Input, 64) If mistake! = Zero
Comments
Post a Comment