-3

This is my first week at college (Cyber security), and I don't have any coding background.

For a python assignment, I have to round the amounts to two decimal places, but if the last decimal is a zero, it should not show in the output. What is the appropriate rounding code I should use?

This is my code:

if (valuta == 1): print("Voor", bedrag, "US Dollar krijgt u ", round(USDollar,2),"Euro, De transactiekosten bedragen", round(DollarTransactiekosten,2), "Euro. U ontvangt",round(AfgerondDollar,2), "Euro" )

Edit: Thanks for all the answers and help guys

Andy Noah
  • 3
  • 2
  • Welcome Andy, can you share any attempts you might have made? Or if you have not made any, explain how you would approach this problem. Providing sample data an expected output as code blocks will get you answers quickly – RichieV Sep 04 '20 at 14:49

1 Answers1

1

It looks like you're new to programming, so here's a few pointers. I'm not going to write all the code you need for an answer here because then how will you learn? Instead, here's the thought process behind coming up with a way to code a solution to your problem.

  1. We have a number x.
  2. We want to round it to two decimal places.. Think about what format specifier you'll use. Let's save this result in str_x.
  3. If the last character in this string is a zero, we want to get rid of it.
  4. What we have now is what we required.
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70