false, 'units' => 0, 'reason' => 'MB_MONEY_PRECISION_INVALID', ); } if ( ! preg_match( '/^-?(?:\d{1,8})(?:\.\d{1,4})?$/', $raw ) ) { return array( 'valid' => false, 'units' => 0, 'reason' => 'MB_MONEY_PRECISION_INVALID', ); } $neg = '-' === $raw[0]; $unsigned = $neg ? substr( $raw, 1 ) : $raw; $dot_pos = strpos( $unsigned, '.' ); if ( false === $dot_pos ) { $int_part = $unsigned; $frac_part = ''; } else { $int_part = substr( $unsigned, 0, $dot_pos ); $frac_part = rtrim( substr( $unsigned, $dot_pos + 1 ), '0' ); } if ( '' !== $frac_part ) { return array( 'valid' => false, 'units' => 0, 'reason' => 'MB_MONEY_PRECISION_INVALID', ); } $units = (int) $int_part; if ( $neg ) { $units = -$units; } return array( 'valid' => true, 'units' => $units, 'reason' => null, ); } }