Skip to content
Encode fractions as HTML entities
Perl
Pull request Compare This branch is even with acme:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib/HTML
t
Build.PL
CHANGES
MANIFEST
META.yml
Makefile.PL
README

README

NAME
    HTML::Fraction - Encode fractions as HTML entities

SYNOPSIS
      my $fraction = HTML::Fraction->new;
      print $fraction->tweak($html);
  
DESCRIPTION
    The HTML::Fraction encodes fractions as HTML entities. Some very common
    fractions have HTML entities (eg 1/2 is ½). Additionally, common
    vulgar fractions have Unicode characters (eg 1/5 is ⅕). This
    module takes a string and encodes fractions as entities: this means that
    it will look pretty in the browser.

    Fractions that are supported: 1/4, 1/2, 3/4, 1/3, 2/3, 1/5, 2/5, 3/5,
    4/5, 1/6, 5/6, 1/8, 3/8, 5/8 and 7/8.

    Fractions may be in the string in the form numerator slash denominator
    ("1/5") or in decimal form ("0.5"). Numbers that do not have exact
    decimal representation must be equal to the fraction to two decimal
    places. This module supports converting whole and fractional decimal
    numbers (e.g. "2.25".)

CONSTRUCTOR
  new
    The constructor takes no arguments:

      my $fraction = HTML::Fraction->new;

METHODS
  tweak
    Encode the fractions in the HTML as HTML entities:

      print $fraction->tweak($html);

  tweak_frac
    Encode the fractions that are in the form "1/3" or "5/6" in the HTML as
    HTML entities, but not decimal fractions of the form "0.5".

  tweak_dec
    Encode the fractions that are in the form "0.5" or "0.5" in the HTML as
    HTML entities, but not fractions of the form "1/2" or "1/3".

AUTHOR
    Leon Brocard, "<acme@astray.com>". Mark Fowler "<mark@twoshortplanks>"
    added some code, and probably some bugs.

COPYRIGHT
    Copyright (C) 2005, Leon Brocard

    This module is free software; you can redistribute it or modify it under
    the same terms as Perl itself.

BUGS
    We don't perform normalisation of the denominator and numerator so "4/6"
    is not converted like "2/3" is. This is intentional

    2.25 doesn't render to the same thing as 2 1/2 (the latter has a space
    between the digit 2 and the fraction.)

Something went wrong with that request. Please try again.