str_float{s:str, f:float, format:str, default:float}
A relation generator. Can convert string s into float f and vice-versa.
For each string that cannot be parsed, no tuple is returned.
If format is given it is treated as a format string. See print for details.
If default is given it is used for f when s is "".
Examples
string to float
str_float(s:="3.142")
| f | format | default |
|---|---|---|
| 3.142 | 0 |
float to string
str_float(f:=42.0)
| s | format | default |
|---|---|---|
| 42 | 0 |
float with format
str_float(f:=3.14159, format:=":.3f")
| s | default |
|---|---|
| 3.142 | 0 |
bulk operation - with some invalid and some empty
d := {s:str}{
["3.142"]
["not a float"]
[""]
["99"]
["-42"]
}
(d & str_float){s, f}
┌───────┬────────┐ │ s │ f │ ├───────┼────────┤ │ │ 0.00 │ │ -42 │ -42.00 │ │ 3.142 │ 3.14 │ │ 99 │ 99.00 │ └───────┴────────┘