如何显示带有两位小数的浮点数? - How to display a float with two decimal places?

问题:

I have a function taking float arguments (generally integers or decimals with one significant digit), and I need to output the values in a string with two decimal places (5 → 5.00, 5.5 → 5.50, etc).我有一个采用浮点参数的函数(通常是整数或带一位有效数字的小数),我需要在一个带有两个小数位(5 → 5.00、5.5 → 5.50 等)的字符串中输出值。 How can I do this in Python?我怎样才能在 Python 中做到这一点?


解决方案:

参考一: https://en.stackoom.com/question/PndW
参考二: https://stackoom.com/question/PndW
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章