在Python 3中,我会
print_me = "Look at this significant figure formatted number: {:.2f}!".format(floating_point_number)
print(print_me)
或者print_me = f"Look at this significant figure formatted number: {floating_point_number:.2f}!"
print(print_me)
在Julia中
print_me = "Look at this significant figure formatted number: $floating_point_number"
print(print_me)
但这将产生如下结果
Look at this significant figure formatted number: 61.61616161616161
我该如何让 Julia 限制其显示的小数位数?需要注意的是,据我所知,必须存储要打印的字符串,这使得使用 @printf
宏成为不可能。
这种方法可以运行,但似乎在风格上不太正确。
floating_point_number = round(floating_point_number,2)
print_me = "Look at this significant figure formatted number: $floating_point_number"
print(print_me)