<?php
$digits = 10;
foreach([7887.0000000000000000, 8667887.0000000000000000, 0.0786451, 1.0786451] as $lastPrice) {
$price = number_format($lastPrice, 16, '.', '');
$price = ltrim($price, '-');
$price = rtrim($price, '0');
list($d, $s) = explode('.', $price);
var_dump($price);
var_dump([$d, $s]);
if ($d !== '0') {
$round = $digits - strlen($d);
} else {
$round = $digits + strlen($s) - strlen(ltrim($s, '0'));
}
var_dump($round);
}
return;
foreach ([7887.0000000000000000, 0.0786451] as $price) {
$maxDigits = 5;
$log = floor(round(log($price) / M_LN10, 10));
var_dump($log);
var_dump((10 ** ($maxDigits - $log)));
}
preferences:
83.56 ms | 402 KiB | 5 Q