'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.
Is there a way to have the results output show 0.00 and 397.00?
Thanks!
Solution 1:[1]
You can try
billables_all["Parts Charged"] = billables_all["Parts Charged"].apply('{0:.2f}'.format)
Solution 2:[2]
In a format string you can set the number of decimal places:
billables_all["Parts Charged"] = f'{billables_all["Parts Charged"]:.2f}'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ynjxsjmh |
Solution 2 |