title: Rounding to 2 decimal places in Python
body: <p>This isn't a duplicate because I have checked everything before this post on this site. I think I have managed to do the first two bullet points. The first one I will do through a string but I am willing to change that if you know another way. The 2nd one is using comma seperators for the $'s. So I will use a float but once again am willing to change if better way is found. <a href="https://i.stack.imgur.com/pfRsw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pfRsw.png" alt="This is the task I have to complete"></a></p>
  
  <p>But I am stuck.
  And the "print("%.2f") % str) is something I found but I need work on rounding to two decimal spaces and the last bullet point.</p>
  
  <p>Code:</p>
  
  <pre><code>import random
  
  
  def random_number():
      random_dollars = random.uniform(1.00, 10000.00)
      print(round(random_dollars, 2))
      print("%.2f") % str
  
  
  print(random_number())
  </code></pre>
  
  <p>Shell:</p>
  
  <pre><code>C:\Users\jacke\PycharmProjects\ASLevelHomeworkWeek18\venv\Scripts\python.exe C:/Users/jacke/PycharmProjects/ASLevelHomeworkWeek18/ASLevelHomeworkWeek18.py 6567.62 Traceback (most recent call last): %.2f File 
  
  C:/Users/jacke/PycharmProjects/ASLevelHomeworkWeek18/ASLevelHomeworkWeek18.py", line 10, in &lt;module&gt; print(random_number()) File
  
  C:/Users/jacke/PycharmProjects/ASLevelHomeworkWeek18/ASLevelHomeworkWeek18.py", line 7, in random_number print("%.2f") % str TypeError: unsupported operand type(s) for %: 'NoneType' and 'type' Process finished with exit code 1 
  </code></pre>