Difference between revisions of "Template:Sigfigs"

From Kerbal Space Program Wiki
Jump to: navigation, search
(Undo revision 58555 by Brendan (talk): well meant but not correct)
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<includeonly>{{#iferror:{{#expr:{{{1|}}}}}|{{{1}}}| <!--
+
<includeonly>{{#ifeq: {{{1}}}|N/A|N/A|<span style="white-space:nowrap;">{{#ifexpr: abs(floor(ln({{{1}}})/ln(10))) + 1>{{{2}}}|{{#formatnum:{{#expr: {{{1}}}/10^floor(ln({{{1}}})/ln(10)) round {{{2}}} - 1}}|{{#expr: {{{2}}} - 1}}|{{DS}}|t}}×10<sup>{{#formatnum:{{#expr: floor(ln({{{1}}})/ln(10))}}|{{DS}}|t}}</sup>|{{#formatnum:{{{1}}}|{{#expr: {{{2}}}-{{#ifexpr: ln({{{1}}}) >= 0|abs(floor(ln({{{1}}})/ln(10)))-1|0}}}}|{{DS}}|t}}}}</span>}}</includeonly><noinclude>Shows a number with the given number of significant figures. Uses the scientific notation if the number is longer than the requested significant figures.
{{#ifeq: {{{1}}}|N/A|N/A|{{#expr: <!--
 
--> floor( 0.5 + <!--
 
-->    {{{1|12345678901234567890}}} <!--
 
-->     / 10^( <!--
 
-->        floor(ln({{{1}}}) / ln(10)) <!--
 
-->         + 1 - {{{2|5}}} <!--
 
-->    ) <!--
 
--> ) <!--
 
--> * ( <!--
 
-->    10^( <!--
 
-->        floor(ln({{{1}}}) / ln(10)) <!--
 
-->        + 1 - {{{2|5}}} <!--
 
-->     ) <!--
 
--> ) <!--
 
}}}}}}</includeonly><noinclude>
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 23: Line 8:
 
|-
 
|-
 
| <pre><nowiki>{{sigfigs|0.123456789012345678|5}}</nowiki></pre> || {{sigfigs|0.123456789012345678|5}}
 
| <pre><nowiki>{{sigfigs|0.123456789012345678|5}}</nowiki></pre> || {{sigfigs|0.123456789012345678|5}}
|-
 
| <pre><nowiki>{{sigfigs|Hello World|5}}</nowiki></pre> || {{sigfigs|Hello World|5}}
 
 
|}
 
|}
  
[[Category:Templates|sigfigs]]
+
[[Category:Templates]]
 
</noinclude>
 
</noinclude>

Latest revision as of 11:16, 16 March 2015

Shows a number with the given number of significant figures. Uses the scientific notation if the number is longer than the requested significant figures.

Usage Produces
{{sigfigs|12345678901234567890|5}}
1.2346×1019
{{sigfigs|0.123456789012345678|5}}
0.12346