Files
php-func-lib/numbers.php
2026-02-15 14:45:02 +01:00

40 lines
872 B
PHP

<?php
declare(strict_types=1);
function decade(int|float|string $zahl): int|float|string
{
if (! is_numeric($zahl) || $zahl == 0)
return $zahl;
$si = array(
- 4 => 'p',
- 3 => 'n',
- 2 => '&mu;',
- 1 => 'm',
0 => '',
1 => 'K',
2 => 'M',
3 => 'G',
4 => 'T'
);
$e = 0;
if ($zahl < 1) {
while ($zahl < 1 || $zahl >= 1000) {
$zahl = $zahl * 1000;
$e --;
}
} else {
while ($zahl < 1 || $zahl >= 1000) {
$zahl = $zahl / 1000;
$e ++;
}
}
return $zahl . ' ' . $si[$e];
}
function onlyNumeric(string $num): string {
return preg_replace("/[^0-9\.\-]+/", "", $num);
}
?>