擅长:python、mysql、java
<p>有新的格式规范,字符串格式<a href="https://docs.python.org/3/library/string.html#format-specification-mini-language" rel="nofollow noreferrer">Specification Mini-Language</a>:</p>
<p>您可以执行以下操作:</p>
<pre><code>"{0:.2f}".format(1.42345) // output 1.42
</code></pre>
<p><strong>注意</strong>上面返回一个字符串。为了得到float,只需用float(…)换行:</p>
<pre><code>float("{0:.2f}".format(1.42345)) // output 1.42
</code></pre>