[英]Round to 2 Decimal Places Even with Zeros
I am currently using the following logic to round to round to 2 decimal places:我目前正在使用以下逻辑四舍五入到小数点后两位:
billables_all["Parts Charged"] = billables_all["Parts Charged"].fillna(0).round(2)
billables_all["Labor Charged"] = billables_all["Labor Charged"].fillna(0).round(2)
billables_all["Travel Charged"] = billables_all["Travel Charged"].fillna(0).round(2)
billables_all["Invoice Amount"] = billables_all["Invoice Amount"].fillna(0).round(2)
billables_all["USD Amount"] = billables_all["USD Amount"].fillna(0).round(2)
However, in the output it appears that it cuts off the 0's.但是,在 output 中,它似乎切断了 0。
Is there a way to have the results output show 0.00 and 397.00?有没有办法让结果 output 显示 0.00 和 397.00?
Thanks!谢谢!
In a format string you can set the number of decimal places:在格式字符串中,您可以设置小数位数:
billables_all["Parts Charged"] = f'{billables_all["Parts Charged"]:.2f}'
You can try你可以试试
billables_all["Parts Charged"] = billables_all["Parts Charged"].apply('{0:.2f}'.format)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.