我曾尝试使用 with-precision
但它没有用:
(.log js/console (with-precision 2 1.2345))
所以我用了
toFixed
:(.log js/console (.toFixed 1.2345 2))
但我觉得这不是这样做的惯用方式。
另外,我不明白为什么
with-precision
不起作用。请启发我...
最佳答案
(ns foo.bar
(:require
[goog.string :as gstring]
[goog.string.format]))
(.log js/console (gstring/format "%.2f" 1.2345))
关于clojurescript - 在 ClojureScript 中,如何显示带有 2 个小数的 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21554191/