<commit_before>package DDG::Goodie::Tips;
use DDG::Goodie;

triggers any => 'tip', 'tips', '%';

handle query_lc => sub {
    return unless my ($p, $is_tip, $sign,$num) = $_ =~/^(\d{1,3})(?: ?%| percent) (?:(tip (?:on|for))|of)(?: an?)? ([\$\-]?)(\d+(\.?)(?(5)\d+))(?: bill)?$/;
    $p /= 100;
    my $t = $p*$num;
    my $tot;

    if ($is_tip) {
	$tot = $num + $t;
    }

    $t = sprintf "%.2f", $t;
    $tot = sprintf "%.2f", $tot if $tot;

    if ($tot) {
	zci answer_type => 'tip';
	return "Tip: \$$t; Total: \$$tot";
    }
    $t = $sign . $t;
    $tot = $sign . $tot if $tot;<commit_msg>Added regexp to match queries like "20% tip of 43.3".<commit_after>package DDG::Goodie::Tips;
use DDG::Goodie;

triggers any => 'tip', 'tips', '%';

handle query_lc => sub {
    return unless my ($p, $is_tip, $sign,$num) = $_ =~/^(\d{1,3})(?: ?%| percent) (?:(tip (?:on|for|of))|of)(?: an?)? ([\$\-]?)(\d+(\.?)(?(5)\d+))(?: bill)?$/;
    $p /= 100;
    my $t = $p*$num;
    my $tot;

    if ($is_tip) {
	$tot = $num + $t;
    }

    $t = sprintf "%.2f", $t;
    $tot = sprintf "%.2f", $tot if $tot;

    if ($tot) {
	zci answer_type => 'tip';
	return "Tip: \$$t; Total: \$$tot";
    }
    $t = $sign . $t;
    $tot = $sign . $tot if $tot;
{'fraction_non_alphanumeric': 0.30008110300081103, 'fraction_numerical': 0.0170316301703163, 'mean_word_length': 2.7621951219512195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '317600', 'n_tokens_mistral': 579, 'n_tokens_neox': 558, 'n_words': 136}