Template:Cents: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Xenwolf (talk | contribs)
Created page with "{{#number_format:{{#expr: 1200*ln({{{1|{{{ratio|2}}}}}})/ln(2)}}|{{{2|{{{precision=3}}}}}}|.|}}<noinclude> This template calculates the cent value of its argument. An optional..."
 
ArrowHead294 (talk | contribs)
mNo edit summary
 
(38 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{#number_format:{{#expr: 1200*ln({{{1|{{{ratio|2}}}}}})/ln(2)}}|{{{2|{{{precision=3}}}}}}|.|}}<noinclude>
{{<includeonly>subst:</includeonly>#number_format: {{<includeonly>subst:</includeonly>#expr: 1200 * ln({{<includeonly>subst:</includeonly>#rmatch: {{{1|{{{ratio|1}}}}}}|^(.*?)[Cc]?$|\1}}) / ln(2)}}|{{{2|{{{prec|0}}}}}}|.|}}{{<includeonly>subst:</includeonly>#switch: {{<includeonly>subst:</includeonly>#rmatch: {{{1|{{{ratio|1}}}}}}|^.*?([Cc]?)$|\1}}|c={{c}}|C={{cent}}|#default=}}<noinclude>
This template calculates the cent value of its argument. An optional second parameter controls the precision, it defaults to 3 decimal places.
{{documentation}}


<big>It requires the MediaWiki [https://www.mediawiki.org/wiki/Extension:NumberFormat Extension:NumberFormat] being [[Special:Version|installed]].</big>
[[Category:Functionality templates]]
 
[[Category:Templates]]
</noinclude>
</noinclude>

Latest revision as of 19:30, 6 August 2025

0

Template documentation[view] [edit] [history] [purge]
This template should always be substituted (i.e. use {{subst:Cents}}).

This template calculates the cent value of its first argument (defaults to 1). An optional second argument controls the precision, it defaults to 0 decimal places.

Usage

Use this template like this

{{subst: cents|ratio|prec}}

Example

This input in the wiki source

{{subst: cents|3/2|5}}

produces the following output

701.95500

Intervals can even be typed as evaluable mathematical expressions. For example:

{{subst: cents|3^12/2^19|5}}

gives:

23.46001

Add in a lowercase C to the end of the expression to add {{c}}:

{{subst: cents|5/4c|2}}

gives:

386.31 ¢

Add in an uppercase C to add {{cent}}:

{{subst: cents|5/4C|2}}

gives:

386.31 ¢

See also