Infer the decimals given a value and a precision value

@param number|string $value
@param number|string $precision
@return int
439637
public static function inferDecimals( $value, $precision )
	{
		if ( is_string( $value ) )
		{
			// BMS 2017-08-22 	Removed this line because functions test 80154 V-05 fails
			//					and none of the XBRL 2.1 conformance tests seem to touch it.
			// $value = trim( $value, "0 " );

			if ( $value == 'INF' ) return "INF";
			$value = intval( $value );
		}

		// BMS 2017-12-18 Changed test to use ===
		if ( $value == 0 || $precision === "INF" ) return INF;
		if ( $precision == 0 ) return false;

		return $precision - intval( floor( log10( abs( $value ) ) ) ) - 1;
	}
189175
public function decimal($values)
    {
        //For reference, this is what typically gets passed to this function:
        //$parts=Array('datatype'=>'decimal', 'precision'=>"$this->wholeSize,$this->decimalSize");
        //DB::requireField($this->tableName, $this->name, "decimal($this->wholeSize,$this->decimalSize)");
        // Avoid empty strings being put in the db
        if ($values['precision'] == '') {
            $precision = 1;
        } else {
            $precision = $values['precision'];
        }

        // Fix format of default value to match precision
        if (isset($values['default']) && is_numeric($values['default'])) {
            $decs = strpos($precision, ',') !== false
                    ? (int) substr($precision, strpos($precision, ',') + 1)
                    : 0;
            $values['default'] = number_format($values['default'], $decs, '.', '');
        } else {
            unset($values['default']);
        }

        return "decimal($precision) not null" . $this->defaultClause($values);
    }
21414
public static function toInteger($value, array $options = array())
    {
        $options['precision'] = 0;
        $options['number_format'] = Zend_Locale_Format::STANDARD;
        return self::toNumber($value, $options);
    }
111561
protected function getExtraLengthBits($value)
    {
        if (($value >= 257 && $value <= 260) || $value === 285) {
            return 0;
        } elseif ($value >= 261 && $value <= 284) {
            return (($value - 257) >> 2) - 1;
        } else {
            throw new Exception\InvalidArgumentException('value', 'Invalid value');
        }
    }
749233
private function computeF1Score(float $precision, float $recall): float
    {
        if (0 == ($divider = $precision + $recall)) {
            return 0.0;
        }

        return 2.0 * (($precision * $recall) / $divider);
    }
246177
private function round($number, $precision, int $mode): Utility
    {
        if ($precision < 0) {
            throw new InvalidNumberException('Precision value should be greater or equal to zero');
        }

        $value = round($number, $precision, $mode);

        return new static($value);
    }
430339
public static final double round(double value, double precision)
   {
      precision = Math.pow(10, precision);
      return Math.round(value * precision) / precision;
   }
1038244
public function setPrecision($precision)
    {
        if (!empty($precision) && ctype_digit(strval($precision))) {
            $this->precision = (int) $precision;
        }

        return $this;
    }
875341
public static function formatToDecimal($value, $decimals = 2)
    {
        if (trim($value) != null) {
            return number_format($value, $decimals, '.', '');
        }
        return null;
    }
1233646
private function integerDivision(DecimalNumber $a, DecimalNumber $b, $precision)
    {
        $dividend = $a->getCoefficient();
        $divisor = new DecimalNumber($b->getCoefficient());
        $dividendLength = strlen($dividend);
        $result = '';
        $exponent = 0;

        $currentSequence = '';
        for ($i = 0; $i < $dividendLength; $i++) {
            // append digits until we get a number big enough to divide
            $currentSequence .= $dividend[$i];

            if ($currentSequence < $divisor) {
                if (!empty($result)) {
                    $result .= '0';
                }
            } else {
                // subtract divisor as many times as we can
                $remainder = new DecimalNumber($currentSequence);
                $multiple = 0;
                do {
                    $multiple++;
                    $remainder = $remainder->minus($divisor);
                } while ($remainder->isGreaterOrEqualThan($divisor));

                $result .= (string) $multiple;

                // reset sequence to the reminder
                $currentSequence = (string) $remainder;
            }

            // add up to $precision decimals
            if ($currentSequence > 0 && $i === $dividendLength - 1 && $precision > 0) {
                // "borrow" up to $precision digits
                --$precision;
                $dividend .= '0';
                $dividendLength++;
                $exponent++;
            }
        }

        $sign = ($a->isNegative() xor $b->isNegative()) ? '-' : '';

        return new DecimalNumber($sign . $result, $exponent);
    }
1142021
public static function fraction($num, float $precision=0.0001) {
		ref\format::fraction($num, $precision);
		return $num;
	}
626082
public static function format($value, $precision = null, $locale = null)
    {
        if ($precision === null) {
            $precision = self::$default_precision;
        }
        if ($locale) {
            $currentLocale = self::$_locale;
            self::$_locale = $locale;
        }
        if (is_array($value)) {
            foreach ($value as &$val) {
                $val = self::format($val, $precision);
            }
            return $value;
        }

        if (self::$_locale !== i18n::get_locale()) {
            self::initVariables();
        }
        if (self::$_decimals === null) {
            self::initVariables();
        }

        $rawValue = self::unformat($value);

        $formattedValue = number_format(
            $rawValue,
            $precision,
            self::$_decimals,
            self::$_thousands
        );

        if ($locale) {
            self::$_locale = $currentLocale;
        }

        return $formattedValue;
    }
986532
public static function decimal($value, $places = 2, $digits = null)
    {
        $digits = $digits > 0
            ? '{' . ((int) $digits) . '}' // 指定位数
            : '+'; // 任意位数

        $decimal = array_shift(array_values(localeconv()));

        return (bool) preg_match('/^[+-]?[0-9]' . $digits . preg_quote($decimal) . '[0-9]{' . ((int) $places) . '}$/D', $value);
    }
1059911
public static function formatToInteger($value, $decimals = 2)
    {
        if (trim($value) != null) {
            return number_format($value, $decimals, '.', '') * 100;
        }
        return null;
    }
706607
public static function round($value, int $precision = null)
    {
        if (!is_numeric($value)) {
            throw new InvalidArgumentException("Value must be numeric");
        }

        return round($value, $precision ?? static::getRoundPrecision());
    }
416548
public static function isInteger($value)
    {
        if (!is_scalar($value) || is_float($value)) {
            return false;
        }
        if (is_int($value)) {
            return true;
        }

        return (bool)preg_match('/^-?[0-9]+$/', $value);
    }
1279811
protected function cast($value)
    {
        if (strlen($value) === 0) {
            return null;
        }
        if ($this->getScale() === 0) {
            return (int)$value;
        }
        return (float)$value;
    }