mirror of
https://github.com/cosmocode/dokuwiki-plugin-struct.git
synced 2025-08-13 13:37:20 +00:00
add eng notation
This commit is contained in:
@ -23,7 +23,8 @@ class Decimal extends AbstractMultiBaseType
|
|||||||
'thousands' => "\xE2\x80\xAF", // narrow no-break space
|
'thousands' => "\xE2\x80\xAF", // narrow no-break space
|
||||||
'trimzeros' => true,
|
'trimzeros' => true,
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
'postfix' => ''
|
'postfix' => '',
|
||||||
|
'engineering' => false
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,6 +37,27 @@ class Decimal extends AbstractMultiBaseType
|
|||||||
*/
|
*/
|
||||||
public function renderValue($value, \Doku_Renderer $R, $mode)
|
public function renderValue($value, \Doku_Renderer $R, $mode)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ($this->config['engineering']) {
|
||||||
|
$unitsh = array('', 'k', 'M', 'G', 'T');
|
||||||
|
$unitsl = array('', 'm', 'µ', 'n', 'p', 'f', 'a');
|
||||||
|
|
||||||
|
$exp = floor(log10($value)/3);
|
||||||
|
|
||||||
|
if ($exp < 0) {
|
||||||
|
$units = $unitsl;
|
||||||
|
$mul = -1;
|
||||||
|
} else {
|
||||||
|
$units = $unitsh;
|
||||||
|
$mul = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$R->cdata($this->config['prefix'] . $value / 10**($exp*3) . "\xE2\x80\xAF" . $units[$exp*$mul] . $this->config['postfix'] );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($this->config['roundto'] == -1) {
|
if ($this->config['roundto'] == -1) {
|
||||||
$value = $this->formatWithoutRounding(
|
$value = $this->formatWithoutRounding(
|
||||||
$value,
|
$value,
|
||||||
@ -56,6 +78,7 @@ class Decimal extends AbstractMultiBaseType
|
|||||||
$value = rtrim($value, $this->config['decpoint']);
|
$value = rtrim($value, $this->config['decpoint']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$R->cdata($this->config['prefix'] . $value . $this->config['postfix'] );
|
$R->cdata($this->config['prefix'] . $value . $this->config['postfix'] );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user