Skip to content

Commit 521d4be

Browse files
committed
catch numbers higher/lower than available prefixes
1 parent 850c936 commit 521d4be

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

_test/Type_Decimal.test.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,15 @@ public function valueProvider()
131131
array('1e9', '1'."\xE2\x80\xAF".'G', '-1', ',', ' ', true, '', '', true),
132132
array('1e12', '1'."\xE2\x80\xAF".'T', '-1', ',', ' ', true, '', '', true),
133133

134-
array('1e4', '10'."\xE2\x80\xAF".'k', '-1', ',', ' ', true, '', '', true),
134+
array('1e4', '10'. "\xE2\x80\xAF".'k', '-1', ',', ' ', true, '', '', true),
135135
array('1e5', '100'."\xE2\x80\xAF".'k', '-1', ',', ' ', true, '', '', true),
136136

137-
array('1e15', '100'."\xE2\x80\xAF".'k', '-1', ',', ' ', true, '', '', true),
137+
array('1e-4', '100'."\xE2\x80\xAF".'µ', '-1', ',', ' ', true, '', '', true),
138+
array('1e-5', '10'. "\xE2\x80\xAF".'µ', '-1', ',', ' ', true, '', '', true),
139+
140+
//test behaviour if number exceeds prefix array
141+
array('1e15', '1000'. "\xE2\x80\xAF".'T', '-1', ',', ' ', true, '', '', true),
142+
array('1e-21', '0.001'."\xE2\x80\xAF".'a', '-1', ',', ' ', true, '', '', true),
138143

139144
);
140145
}

types/Decimal.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ public function renderValue($value, \Doku_Renderer $R, $mode)
4646

4747
if ($exp < 0) {
4848
$units = $unitsl;
49-
$mul = -1;
49+
$pfkey = -1 * $exp;
5050
} else {
5151
$units = $unitsh;
52-
$mul = 1;
52+
$pfkey = $exp;
5353
}
5454

55+
if (count($units) <= ($pfkey+1)) {
56+
$pfkey = sizeof($units)-1;
57+
$exp = $pfkey * $exp/abs($exp);
58+
}
5559

56-
$R->cdata($this->config['prefix'] . $value / 10**($exp*3) . "\xE2\x80\xAF" . $units[$exp*$mul] . $this->config['postfix'] );
60+
$R->cdata($this->config['prefix'] . $value / 10**($exp*3) . "\xE2\x80\xAF" . $units[$pfkey] . $this->config['postfix'] );
5761
return true;
5862
}
5963

0 commit comments

Comments
 (0)