Removes trailing zeros for a numeric value expressed as a string.

@param $num

@return string
334475
private static function removeTrailingZeros($num)
    {
        // Only do this if number has a decimal value.
        if (strstr($num, '.')) {
            $num  = rtrim($num, '0');
            $last = substr($num, strlen($num) - 1, 1) == '.';
            $num  = $last ? substr($num, 0, strlen($num) - 1) : $num;

            return $num;
        } else {
            // No decimal value, don't modify number
            return $num;
        }
    }
1337436
def remove_leading_zeros(num: str) -> str:
    
    if not num:
        return num
    if num.startswith('M'):
        ret = 'M' + num[1:].lstrip('0')
    elif num.startswith('-'):
        ret = '-' + num[1:].lstrip('0')
    else:
        ret = num.lstrip('0')
    return '0' if ret in ('', 'M', '-') else ret
565882
public static function trim($n)
    {
        $float         = floatval($n);
        $decimalPlaces = 0;

        // If the number rounded to $decimalPlaces isn't equal to the float val, add another decimal place and try again
        while ($float != round($float, $decimalPlaces)) {
            $decimalPlaces++;
        }

        $decimalPlaces = ($decimalPlaces < 2) ? 2 : $decimalPlaces;

        return number_format($float, $decimalPlaces, ".", "");
    }
281709
public function readBytes($num)
    {
        $returnValue = substr($this->_data, $this->_position, $num);
        $this->_position += $num;

        return $returnValue;
    }
53915
public function eq($num) {
        if (!$this->_isValid) {
            return $this;
        }

        if ($this->_unsafeVar != $num) {
            $this->_isValid = false;
        }
        return $this;
    }
310394
public static function lowerRoman(int $num): string
    {
        $roman = static::upperRoman($num);

        return StringHelper::toLowerCase($roman);
    }
326486
public static function integerAsOptions($num)
    {
        $options = [];

        for ($i = 0; $i <= $num; $i++) {
            $options[] = $i;
        }

        shuffle($options);

        return $options;
    }
230677
private function _convert_number(&$num)
    {
        if (!empty($this->_params['only_integer']))
            $num = (int)$num;
        else
            $num = (float)$num;
    }
821517
private function encodeNumber($num)
    {
        $encodeString = '';

        while ($num >= 0x20) {
            $nextValue = (0x20 | ($num & 0x1f)) + 63;
            $encodeString .= chr($nextValue);
            $num >>= 5;
        }
        $finalValue = $num + 63;
        $encodeString .= chr($finalValue);
        return $encodeString;
    }
781727
protected function readIntegerList($num)
    {
        if ($this->littleEndian) {
            return unpack('V' . $num, fread($this->file, 4 * $num));
        }

        return unpack('N' . $num, fread($this->file, 4 * $num));
    }
304424
public static function ToString( $value )
	{
		if ( is_string( $value ) )

			return $value;

		if ( is_null( $value ) )

			return "false";

		if ( is_bool( $value ) )

			return $value ? "true" : "false";

		if ( $value instanceof TrueValue )

			return "true";

		if ( $value instanceof FalseValue )

			return "false";

		if ( $value instanceof Integer )

			return $value->ToString( null );

		if ( $value instanceof DecimalValue )

			return $value->getRound( 18 )->ToString( null );

		if ( is_numeric( $value ) && ( is_int( $value ) || $value == PHP_INT_MIN ) ) // PHP does not seem to detect PHP_INT_MIN as an int

			return $value . "";

		if ( is_numeric( $value ) && is_nan( $value ) )
		{
			return "NaN";
		}

		if ( is_numeric( $value ) && is_double( $value ) )
		{
			// Using sprintf( "%e", $value ) is not good enough because it will
			// only produce number with a maximum of 7 significant digits
			/* if( preg_match( "/^(?<sign>-)?(?<zeros>0\.0*)/", $value, $m ) )
			{
				$zeroes = strlen( $m['zeros'] );
				$sign = strlen( $m['sign'] );
				return ( $sign ? "-" : "" ) . substr( $value, $zeroes + $sign, 1 ) . rtrim( "." . substr( $value, $zeroes + $sign + 1 ), "0." ) . "E-" . ( $zeroes-1 );
			}
			else
			 */
			if( preg_match( "/^(?<sign>-)?(?<digits>\d{7,})(?:\.(?<decimals>\d+))?/", $value, $m ) )
			{
				$zeroes = strlen( $m['digits'] );
				$sign = strlen( $m['sign'] );
				$d = rtrim( "." . substr( $m['digits'], 1 ) . ( isset( $m['decimals'] ) ? $m['decimals'] : "" ), "0." );
				if ( empty( $d ) ) $d = ".0";
				$x = ( $sign ? "-" : "" ) . substr( $value, 0 + $sign, 1 ) . $d . "E" . ( $zeroes - 1 );
				return $x;
			}

			return str_replace( "+", "", $value . "" );
		}

		if ( $value instanceof \DateInterval )
		{
			return ( new DurationValue( $value ) )->ToString();
			// return ( new YearMonthDurationValue( $value ) )->ToString();
			// return ( new DayTimeDurationValue( $value ) )->ToString();
		}

		if ( $value instanceof \DateTime )
		{
			$format = "";
			if ( property_exists( $value, "isDate" ) && $value->isDate ) $format .= "Y-m-d";
			if ( property_exists( $value, "isTime" ) && $value->isTime ) $format .= ( empty( $format ) ? "" :"\T" ) . "H:i:s";
			$format .= ( $value->getTimezone()->getName() == date_default_timezone_get() ? "" : "P" );
			return  $value->format( $format ); // DateTimeValue::fromDate( false, $value ) )->ToString();
		}

		return $value->ToString();
	}
1058684
private function parseValue($value) {
        if(is_numeric($value)) {
            return $value + 0;
        } elseif($value === "true") {
            return true;
        } elseif($value === "false") {
            return false;
        } elseif(is_array($value)) {
            return $value;
        }

        return addslashes(trim($value));
    }
846072
private function imbReverseUs($num)
	{
		$rev = 0;
		for ($i = 0; $i < 16; ++$i) {
			$rev <<= 1;
			$rev |= ($num & 1);
			$num >>= 1;
		}
		return $rev;
	}
308625
private function splitNumber($num)
    {
        if (is_string($num)) {
            $ret = array();

            $strlen = strlen($num);
            $first  = substr($num, 0, $strlen%3);

            preg_match_all('/\d{3}/', substr($num, $strlen%3, $strlen), $m);

            $ret =& $m[0];
            if ($first) {
                array_unshift($ret, $first);
            }
            return $ret;
        }

        return explode(' ', number_format($num, 0, '', ' ')); // a faster version for integers
    }
946794
private static function utf8($num) {
    if ($num <=     0x7F) return chr($num);
    if ($num <=    0x7FF) return chr(($num >>  6) + 192) . chr(( $num        & 63) + 128);
    if ($num <=   0xFFFF) return chr(($num >> 12) + 224) . chr((($num >>  6) & 63) + 128) . chr(( $num       & 63) + 128);
    if ($num <= 0x1FFFFF) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
    return '';
  }
334115
public function drop( $num ) {
		if ( $num > $this->count() ) {
			$num = $this->count();
		}

		return $this->slice( $num, $this->count() );
	}
1183069
public static function digits($value)
    {
        // we need to remove - and + because they're allowed in the filter
        $cleaned = str_replace(['-', '+'], '', $value);
        $cleaned = filter_var($cleaned, FILTER_SANITIZE_NUMBER_INT);

        return $cleaned;
    }