且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python中小数点后的浮点数加零

更新时间:2023-02-21 16:30:56

格式化到小数点后6位:

Format it to 6 decimal places:

format(value, '.6f')

演示:

>>> format(2.0, '.6f')
'2.000000'

format() 函数按照给定的格式化说明将值转换为字符串.

The format() function turns values to strings following the formatting instructions given.