fix(query-function): convert num string to float

pull/2461/head
rcmerci 2021-07-20 11:43:46 +08:00 committed by Tienson Qin
parent b3931bedb1
commit c2978785d9
2 changed files with 6 additions and 2 deletions

View File

@ -12,7 +12,9 @@
[s]
(try
(sci/eval-string s {:bindings {'sum sum
'average average}})
'average average
'parseFloat js/parseFloat
'isNaN js/isNaN}})
(catch js/Error e
(println "Query: sci eval failed:")
(js/console.error e))))

View File

@ -38,7 +38,9 @@
(let [vals (map #(get-in % [:block/properties f]) result)
int? (some integer? vals)]
`(~'fn [~'b]
(~'let [~'result (~'get-in ~'b [:block/properties ~f])]
(~'let [~'result-str (~'get-in ~'b [:block/properties ~f])
~'result-num (~'parseFloat ~'result-str)
~'result (if (~'isNaN ~'result-num) ~'result-str ~'result-num)]
(~'or ~'result (~'when ~int? 0))))))
:else