title: Python - how to define a rounding scale for Decimal.quantize
body: <p>I wrote a function for rounding numbers to a certain number of digits on right side of dot. But I still don't understand how to properly define a scale to be used with quantize.</p>
  <p>In the below example, <code>res1</code> and <code>res2</code> return the expected result. I found different examples for defining scale to have 2 numbers after the floating point. What is the difference between using &quot;1.00&quot; and &quot;0.01&quot;? Both seem to work the same way.</p>
  <p>As for <code>res3</code> when I pass a float to the Decimal constructor to get number_3 - <code>ROUND_HALF_UP</code> doesn't seem to work there. Why does this happen? How should I define scale for Decimals created from float?</p>
  <p>In case when I get floats as an input is the only way to get quantize work - first convert a float to a string?</p>
  <pre><code>from decimal import Decimal, ROUND_HALF_UP
  
  
  def custom_round(dec: Decimal, scale, rounding_mode):
      return dec.quantize(Decimal(scale), rounding_mode)
  
  
  number_1 = Decimal(&quot;10.026&quot;)
  res1 = custom_round(number_1, &quot;1.00&quot;, ROUND_HALF_UP)
  print(res1) # 10.03
  
  number_2 = Decimal(&quot;28.525&quot;)
  res2 = custom_round(number_2, &quot;0.01&quot;, ROUND_HALF_UP)
  print(res2) # 28.53
  
  number_3 = Decimal(28.525)
  res3 = custom_round(number_3, &quot;0.01&quot;, ROUND_HALF_UP)
  print(res3) # 28.52 
  </code></pre>