<div class="gmail_quote">On Jan 5, 2008 5:54 PM,  &lt;<a href="mailto:glyph@divmod.com" target="_blank">glyph@divmod.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>At first I didn&#39;t realize why I&#39;d missed this feature. &nbsp;While the<br></div>rounding *modes* are well documented, though, after 20 minutes of<br>reading documentation I still haven&#39;t found a method or function that
<br>simply rounds a decimal to a given significant digit. &nbsp;Is there one,<br>should there be one, or is the user simply meant to use Context.quantize<br>with appropriate arguments?<br><div><div></div><div></div>
</div></blockquote><div><br></div><div>quantize is about as close as it gets. &nbsp;Note that it&#39;s a Decimal method as well as a Context method, so you can invoke it directly on a given decimal:
</div><div><br></div><div><div>&gt;&gt;&gt; Decimal(&quot;2.34567&quot;).quantize(Decimal(&quot;0.01&quot;))</div><div>Decimal(&quot;2.35&quot;)</div><div><br>
</div><div>I&#39;ve also occasionally felt a need for a simple rounding function that isn&#39;t affected by context. &nbsp;Would others be interested in such a function being added to Decimal? &nbsp;I guess there are two possibly useful operations: &nbsp;(1) round to a particular decimal place (
e.g. nearest ten, nearest hundredth, ..) and (2) to round to a particular number of significant digits; &nbsp;in both cases, the user should be able to specify the desired rounding mode. &nbsp;And for each operation, it might also be useful to specify whether the result should be padded with zeros to the desired length or not. &nbsp;(
i.e. when rounding 3.399 to 3 significant places, should it produce 3.4 or 3.40?)<br></div><div><br class="webkit-block-placeholder"></div><div>Any thoughts?</div><div><br class="webkit-block-placeholder"></div><div>Mark</div>
</div></div>