晚上好,
我想在StringBuilder中格式化Scala中的浮点数。下面的代码有效,但很冗长。当然,有一种更简洁的方法可以做同样的事情。
谢谢。
var myDouble: Double = 1.23456789
val stringBuilder = StringBuilder.newBuilder
stringBuilder.append(s"My double: ${BigDecimal(myDouble).setScale(5, BigDecimal.RoundingMode.HALF_UP)}")
println(stringBuilder.toString())
答案 0 :(得分:1)
这样的东西?
pip install pyparsing
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 72, in <module>
import packaging.requirements
File "/usr/local/lib/python2.7/dist-packages/packaging/requirements.py", line 9, in <module>
from pyparsing import stringStart, stringEnd, originalTextFor, ParseException
ImportError: No module named pyparsing