<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.freecapitalists.org/index.php?action=history&amp;feed=atom&amp;title=Template%3AGetprecision%2Fdoc</id>
	<title>Template:Getprecision/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.freecapitalists.org/index.php?action=history&amp;feed=atom&amp;title=Template%3AGetprecision%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://wiki.freecapitalists.org/index.php?title=Template:Getprecision/doc&amp;action=history"/>
	<updated>2026-08-16T06:19:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://wiki.freecapitalists.org/index.php?title=Template:Getprecision/doc&amp;diff=15127&amp;oldid=prev</id>
		<title>John James: Created page with &quot;{{Documentation subpage}} {{Wikipedia text|Template:Getprecision/doc|412746627}} &lt;!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE --&gt; __NOTOC__ The &#039;&#039;&#039;Templat...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.freecapitalists.org/index.php?title=Template:Getprecision/doc&amp;diff=15127&amp;oldid=prev"/>
		<updated>2011-05-06T22:45:38Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Documentation subpage}} {{Wikipedia text|Template:Getprecision/doc|412746627}} &amp;lt;!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE --&amp;gt; __NOTOC__ The &amp;#039;&amp;#039;&amp;#039;Templat...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Documentation subpage}}&lt;br /&gt;
{{Wikipedia text|Template:Getprecision/doc|412746627}}&lt;br /&gt;
&amp;lt;!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE --&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Template:Getprecision&amp;#039;&amp;#039;&amp;#039; determines the precision (as a count of decimal digits) for any amount, large or negative, using&lt;br /&gt;
a fast algorithm. It can also handle a trailing decimal point (such&lt;br /&gt;
as &amp;quot;15.&amp;quot; or &amp;quot;-41.&amp;quot;) or trailing zeroes (such as &amp;quot;15.34000&amp;quot; having precision as 5 decimal digits).&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
Some examples:&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| 0}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| 0}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| 1}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| 1}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| 22.45}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| 22.45}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| 22.12345}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| 22.12345}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| 22}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| 22}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| 22000}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| 22000}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| -15.275}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| -15.275}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| -15.2500}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| -15.2500}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{Getprecision |23000222000111.432}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{Getprecision |23000222000111.432}}&lt;br /&gt;
&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision| -15.123}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision| -15.123}}&lt;br /&gt;
:: &amp;lt;nowiki&amp;gt;{{precision| -15.123}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{precision| -15.123}} [ Getprecision handles negatives, but not {precision} ]&lt;br /&gt;
&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision|0.09}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision|0.09}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision|0.88}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision|0.88}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision|880000}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision|880000}}&lt;br /&gt;
:* &amp;lt;nowiki&amp;gt;{{getprecision|90000000}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision|90000000}}&lt;br /&gt;
&lt;br /&gt;
===Known bugs===&lt;br /&gt;
* For numbers in scientific notation, the precision is typically returned as too low by 1 decimal place. Example: &amp;lt;nowiki&amp;gt;{{getprecision |7.1234E+06}}&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{getprecision|7.1234E+06}} (should be precision as 4 decimal digits, not 3).&lt;br /&gt;
* Large numbers are limited to 11 trailing zeroes, so even larger numbers still report precision as being -11, such as 9 trillion: {&amp;amp;#123;getprecision|9000000000000}} &amp;amp;rarr; {{getprecision|9000000000000}} (should be: -12).&lt;br /&gt;
&lt;br /&gt;
===Technical notes===&lt;br /&gt;
*NOTE A1: This template determines the precision of decimals by counting the length of the numeric string (in a #switch comparing lengths of padded strings), then subtracting integer length, minus the decimal point, and minus 1 if negative. For integers, 1 place is subtracted for each trailing 0 on the integer. For fractions, any prior count is cleared x 0, then size is logarithm of denominator divided by log 10: (..prior...)*0 + floor(logn denom / logn 10 - .01) + 1.&lt;br /&gt;
*NOTE D2: The check, for whole integers, compares the amount versus appending &amp;quot;0&amp;quot; at the end: when the amount is a decimal, then the value is unchanged by appending 0 at the end: so 5.23 = 5.230 is true, whereas for whole integers, it would be: 5 = 50 as false, due to values becoming n*10 for integer n. So, for integer n, the check rejects: n = n0 as false; hence n is integer.&lt;br /&gt;
*NOTE M3: The magnitude of the integer portion is calculated by logarithm of the floor of absolute value (divided by [[natural logarithm]] of 10 to adjust for e=2.71828*), as: ln (floor( abs({{{1|-0.050067}}}) )+0.99 )/ln10 Function floor(x) trims the decimal part, to leave the whole count: 0-9 yield 0, 10-19 as 1, 1000-1999 as 3. The abs(x) avoids floor of negatives, floor(-0.1)= -1, hence using abs(x) ensures -0.1 floors to 0 not -1. Near zero, the +0.99 avoids invalid log of 0, but does not round-up any decimals, already floored as nnn.00. Complexity is 6 operations: floor of abs( {1} ) +0.99 then logn div logn10, then floor that logarithm ratio. Decimals -1 &amp;lt; x &amp;lt; 1 yield -1, avoiding log 0.001 = -3.&lt;br /&gt;
*NOTE N4: Nesting of if-else and nested templates is kept to a minimum, due to the MediaWiki 1.6 limit of 40 levels of if-logic for all nested templates used together. Template {ordomag} was omitted to avoid 2 more levels of nested templates. Template {Precision} had 8 levels, and this template was trimmed to only 5 levels.&lt;br /&gt;
*NOTE S5: The #switch is run with &amp;quot;x&amp;quot; prepended in front of the amount, otherwise a #switch will compare as numeric where &amp;quot;2&amp;quot; would match &amp;quot;2.0&amp;quot; even though &amp;quot;2&amp;quot; is length 1 so &amp;quot;x2&amp;quot; no longer matches with &amp;quot;x2.0&amp;quot; as non-numeric. The #switch will exit on the first match, so smaller lengths are compared first, to avoid extra comparisons for more rare, longer numeric strings up to 41 long.&lt;br /&gt;
*NOTE W6: The check for integers with whole end-zeroes uses typical n=n/10*10, for each power of 10, where whole millions match: &amp;lt;nowiki&amp;gt;{{#ifexpr: {1}=floor( {1}/1E6 )*1E6| }}&amp;lt;/nowiki&amp;gt; Previously, {Precision} had tried to use &amp;quot;round&amp;quot; to detect end-zeroes but &amp;quot;round&amp;quot; loses precision at -5, so, n00000 round -5 differs from n00000 slightly, and comparisons to exact rounded amounts failed to match some numbers when 6 or more zeroes &amp;quot;n000000&amp;quot;.&lt;br /&gt;
*NOTE Z7: The check on zero for any .00000 compares adding 1 to the amount, versus appending &amp;quot;1&amp;quot; at the end: if the amount is a decimal, then adding 1 will be larger than appending 1 at the end: 0.00 + 1 &amp;gt; 0.001, whereas for whole zero, it would be: 0+1 &amp;gt; 01 as false, due to the value being the same. So, for integer 0, the check rejects: 0+1 &amp;gt; 01 as false; hence whole 0 is integer.&lt;br /&gt;
&lt;br /&gt;
===History===&lt;br /&gt;
*15Aug10 Created to get precision even if large or negative.&lt;br /&gt;
*15Aug10 Put NOTES comments to explain template coding.&lt;br /&gt;
*15Aug10 Put HISTORY comments to log major changes.&lt;br /&gt;
*18Aug10 Fixed to handle zero: 0 as 0, 0.000 as 3, etc.&lt;br /&gt;
*04Sep10 Fixed to handle decimals between 0~1 (by round 0).&lt;br /&gt;
*04Sep10 Updated NOTES to explain the check appending 0 or 1.&lt;br /&gt;
*03Jan11 Fix integer end-zeroes: 50 as -1, 500 as -2, 5000 -3.&lt;br /&gt;
*03Jan11 Omit {Order of Magnitude} for 2 levels less nesting.&lt;br /&gt;
*03Jan11 Omit {Str_len} for 8 fewer levels of 40-nest limit.&lt;br /&gt;
*03Jan11 Put &amp;quot;noinclude&amp;quot; around all inter-line HTML comments.&lt;br /&gt;
*03Jan11 Allow fraction &amp;quot;/&amp;quot;: floor(logn denom/logn 10 -.01)+1.&lt;br /&gt;
&lt;br /&gt;
===See also===&lt;br /&gt;
* [[Template:Precision]] - get precision of positive numbers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;&lt;br /&gt;
&amp;lt;!-- CATEGORIES AND INTERWIKIS HERE, THANKS --&amp;gt;&lt;br /&gt;
[[Category:Mathematical function templates]]&lt;br /&gt;
[[Category:Templates with minimal expansion depth]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>John James</name></author>
	</entry>
</feed>