perl -e 'use Number::Format qw(format_number); print format_number(12345678987654321)."\n";'
####
round() overflow. Try smaller precision or use Math::BigFloat at -e line 1.
##
##
perl -e 'use Util::Number qw(commify); print commify(12345678987654321)."\n";'
##
##
12,345,678,987,654,321
##
##
Argument "16725th" isn't numeric in numeric comparison (<=>) at /home/me/perl5/lib/perl5/Number/Format.pm line 599.
##
##
Happy 16,725th unbirthday, Aleena! You have 32 days until your next birthday on July 10, 2017.
##
##
package Util::Number;
use strict;
use warnings FATAL => qw( all );
use Exporter qw(import);
our @EXPORT_OK = qw(commify round pretty_number);
# commify was found in the perlfaq5 to put commas in numbers.
sub commify {
local $_ = shift;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}
# sprintf written by james2vegas on PerlMonks.
sub round {
my ($number, $precision) = @_;
my $rounded = $number =~ /\./ ? sprintf("%.${precision}f", $number) : $number;
return $rounded;
}
sub pretty_number {
my ($number, $precision) = @_;
my $pretty_number = commify(round($number, $precision));
return $pretty_number;
}
=head1 NAME
B adds commas, rounds, and returns pretty numbers.
=head1 SYNOPSIS
use Util::Number qw(commify round pretty_number);
my $comma_number = commify(2468);
# returns 2,468
my $rounded_number = round(0.2468, 3);
# returns .247
my $pretty_number = pretty_number(2468.13579, 3);
# returns 2,468.136
=head1 DESCRIPTION
B contains three subroutines that make numbers prettier: C, C, and C.
=head2 commify
B> returns a number with commas between every three digits in the number.
The code was found in L.
=head2 round
B> rounds a decimal number by a set precision. If you want the number returned with three digits after the decimal, the precision would be set to 3.
round($number, $precision);
=head2 pretty_number
B> puts commify and round together so you can get rounded numbers with commas.
pretty_number($number, $precision);
=head1 AUTHOR
Lady Aleena with help
=cut
1;
##
##
package Random::Month;
use strict;
use warnings FATAL => qw( all );
use Exporter qw(import);
our @EXPORT_OK = qw(random_month);
use Fancy::Rand qw(fancy_rand);
my %months = (
'English' => [qw(January February March April May June July August Spetember October November December)],
'English abbr' => [qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Now Dec)],
'Dutch' => [qw(januari februari maart april mei juni juli augustus september oktober november december)],
'French' => [qw(janvier février mars avril mai juin juillet aoűt septembre octobre novembre décembre)],
'German' => [qw(Januar Februar März April Mai Juni Juli August September Oktober November Dezember)],
'Greek' => [qw(Ianuários Fevruários Mártios Aprílios Máios Iúnios Iúlios Avghustos Septémvrios Októvrios Noémvrios Thekémvrios)],
'Italian' => [qw(gennaio febbraio marzo aprile maggio giugno luglio agosto settembre ottobre novembre dicembre)],
'Spanish' => [qw(enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre)],
);
# I wrote this hash for another reason, but Date::Calc killed the need for the original purpose.
sub random_month {
my ($user_language, $user_additions) = @_;
my $random_month = fancy_rand(\%months, $user_language, { caller => 'random_month', additions => $user_additions ? $user_additions : undef });
return $random_month;
}
=head1 NAME
B selects a random month by language.
=head1 SYNOPSIS
use Random::Month qw(random_month);
my $random_month = random_month();
my $random_English_month = random_month('English');
my $random_Dutch_month = random_month('Dutch');
my $random_French_month = random_month('French');
my $random_German_month = random_month('German');
my $random_Greek_month = random_month('Greek');
my $random_Italian_month = random_month('Italian');
my $random_Spanish_month = rnadom_month('Spanish');
my $random_English_month_abbr = random_month('English abbr');
print random_month('help') # get random_month options
=head1 AUTHOR
Lady Aleena
=cut
1;