StringToFloat64 converts a string to a float includes replacement of $ and other monetary format identifiers. May return math.NaN
(s string)
| 367 | // includes replacement of $ and other monetary format identifiers. |
| 368 | // May return math.NaN |
| 369 | func StringToFloat64(s string) (float64, bool) { |
| 370 | if s == "" { |
| 371 | return math.NaN(), false |
| 372 | } |
| 373 | f, err := strconv.ParseFloat(s, 64) |
| 374 | if err == nil { |
| 375 | return f, true |
| 376 | } |
| 377 | s = intStrReplacer.Replace(s) |
| 378 | f, err = strconv.ParseFloat(s, 64) |
| 379 | if err == nil { |
| 380 | return f, true |
| 381 | } |
| 382 | return math.NaN(), false |
| 383 | } |
| 384 | |
| 385 | // Some strings we are trying to convert into Numbers are messy |
| 386 | // $3.12 etc, lets replace them and retry conversion again |
no outgoing calls