Lingua::EN::Fractions - convert "3/4" into "three quarters", etc
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);
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.
fraction2words
undef
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".
'5/2'
At the moment it's not very robust to weird inputs. I may add support for Unicode fractions as well.
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.
https://github.com/neilbowers/Lingua-EN-Fractions
Neil Bowers <neilb@cpan.org>
This module was suggested by Sean Burke, who created the other Lingua::EN::* modules that I now maintain.
Lingua::EN::*
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.
To install Lingua::EN::Fractions, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lingua::EN::Fractions
CPAN shell
perl -MCPAN -e shell install Lingua::EN::Fractions
For more information on module installation, please visit the detailed CPAN module installation guide.