NAME
Lingua::EN::Fractions - convert "3/4" into "three quarters", etc
SYNOPSIS
use Lingua::EN::Fractions qw/ fraction2words /;
my $fraction = '3/4';
my $as_words = fraction2words($fraction);
Or using Number::Fraction:
use Number::Fraction;
my $fraction = Number::Fraction->new(2, 7);
my $as_words = fraction2words($fraction);
DESCRIPTION
This module provides a function, fraction2words
, which takes a string containing a fraction and returns the English phrase for that fraction. If no fraction was found in the input, then undef
is returned.
For example
fraction2words('1/2'); # "one half"
fraction2words('3/4'); # "three quarters"
fraction2words('5/17'); # "five seventeenths"
fraction2words('5'); # undef
fraction2words('-3/5'); # "minus three fifths"
You can also pass in a fraction represented using Number::Fraction:
$fraction = Number::Fraction->new(2, 7);
$as_words = fraction2words($fraction); # "two sevenths"
At the moment, no attempt is made to simplify the fraction, so '5/2'
will return "five halves" rather than "two and a half".
At the moment it's not very robust to weird inputs. I may add support for Unicode fractions as well.
SEE ALSO
Lingua::EN::Numbers, Lingua::EN::Numbers::Ordinate, Lingua::EN::Numbers::Years - other modules for converting numbers into words.
Number::Fraction - a class for representing fractions and operations on them.
REPOSITORY
https://github.com/neilbowers/Lingua-EN-Fractions
AUTHOR
Neil Bowers <neilb@cpan.org>
This module was suggested by Sean Burke, who created the other Lingua::EN::*
modules that I now maintain.
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Neil Bowers <neilb@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.