kmccarthy9
kmccarthy9

Reputation: 15

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. enter image description here

Is there a way to have the results output show 0.00 and 397.00?

Thanks!

Upvotes: 0

Views: 1387

Answers (2)

Ynjxsjmh
Ynjxsjmh

Reputation: 30012

You can try

billables_all["Parts Charged"] = billables_all["Parts Charged"].apply('{0:.2f}'.format)

Upvotes: 0

linuskmr
linuskmr

Reputation: 834

In a format string you can set the number of decimal places:

billables_all["Parts Charged"] = f'{billables_all["Parts Charged"]:.2f}'

Upvotes: 1

Related Questions