RosettaCodeData/Task/Determine-if-a-string-is-numeric/Odin/determine-if-a-string-is-numeric.odin
2023-07-01 13:44:08 -04:00

25 lines
433 B
Odin

package main
import "core:strconv"
import "core:fmt"
is_numeric :: proc(s: string) -> bool {
_, ok := strconv.parse_f32(s)
return ok
}
main :: proc() {
strings := []string{"1", "3.14", "-100", "1e2", "Inf", "rose"}
for s in strings {
fmt.println(s, "is", is_numeric(s) ? "numeric" : "not numeric")
}
}
/* Output:
1 is numeric
3.14 is numeric
-100 is numeric
1e2 is numeric
Inf is not numeric
rose is not numeric
*/