Template:Calculate increment
This template takes two numbers and calculates a suitable increment for {{scalemarkers}} based on the difference between these numbers. Increments are 1, 2 or 5 times an appropriate power of 10.
These numbers, the from value and the to value, are input as unnamed parameters.
{{calculate increment|p1|p2}}The absolute value, d, of the difference between these is calculated.
This can be expressed in scientific notation as follows.
Where 1 ≤ a < 10 and n is an integer.
The output of the template is as follows.
| For | 1 ≤ a | < 1.35 | the output is the number 1 × 10n − 1 |
| For | 1.35 ≤ a | < 3.45 | the output is the number 2 × 10n − 1 |
| For | 3.45 ≤ a | < 6.95 | the output is the number 5 × 10n − 1 |
| For | 6.95 ≤ a | < 10 | the output is the number 1 × 10n |
"{{calculate increment|1|5}}" gives "0.5
" [1]
"{{calculate increment|10|20}}" gives "1
" [2]
"{{calculate increment|10|50}}" gives "5
" [3]
"{{calculate increment|100|250}}" gives "20
" [4]
"{{calculate increment|1000|2000}}" gives "100
" [5]
"{{calculate increment|2000|7500}}" gives "500
" [6]
"{{calculate increment|100000|750000}}" gives "50000
" [7]
The main template page calculates d, the absolute value of the difference between the two inputs. Using {{order of magnitude}} the order of magnitude, n, of d is calculated. d and 10n − 1 are sent as parameters 1 and 2 respectively to a subpage, {{calculate increment/calc}}. This subtemplate uses a #switch to determine the correct factor, 1, 2, 5 or 10, then multiplies by 10n − 1.
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.