如何顯示帶有兩位小數的浮點數? - 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章