.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Math::Round::Var 3" .TH Math::Round::Var 3 "2008-01-07" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" Math::Round::Var \- Variations on rounding. .SH "SYNOPSIS" .IX Header "SYNOPSIS" Simple decimal rounding: .PP .Vb 6 \& use Math::Round::Var; \& my $rnd = Math::Round::Var->new(0.01); \& # rounds to two decimal places: \& my $num = 399886.758673; \& $num = $rnd->round($num); \& print "$num\en"; # 399886.76 .Ve .PP Now it all makes sense. .PP .Vb 7 \& #!/usr/bin/perl \& use Math::Round::Var; \& my $scheme = shift; # let user specify the rounding \& my $num1 = shift; \& my $rnd = Math::Round::Var->new($scheme); \& my $num2 = $rnd->round($num1); \& print "$num1 rounds to $num2 according to scheme: $scheme\en"; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module gives you the ability to round numbers to either decimal or fractional precision while encapsulating the rounding precision in an object. This allows scripts and modules to maintain multiple precision values as objects. .PP It also implements flexible scheme parsing, so that your programs and modules can offload the how-to-round decisions to this module. .SH "AUTHOR" .IX Header "AUTHOR" Eric L. Wilhelm .PP http://scratchcomputing.com .SH "COPYRIGHT" .IX Header "COPYRIGHT" This module is copyright (C) 2003\-2006 by Eric L. Wilhelm. .SH "LICENSE" .IX Header "LICENSE" This module is distributed under the same terms as Perl. See the Perl source package for details. .PP You may use this software under one of the following licenses: .PP .Vb 4 \& (1) GNU General Public License \& (found at http://www.gnu.org/copyleft/gpl.html) \& (2) Artistic License \& (found at http://www.perl.com/pub/language/misc/Artistic.html) .Ve .SH "Front-End Constructor" .IX Header "Front-End Constructor" The Math::Round::Var\->\fInew()\fR constructor only decides between the sub-packages based on the format of your precision argument. .PP This is the extent of the purpose of the Math::Round::Var class. .Sh "new" .IX Subsection "new" .Vb 1 \& Math::Round::Var->new($precision); .Ve .Sh "format_of" .IX Subsection "format_of" Returns \*(L"decimal\*(R" or \*(L"fraction\*(R" for \f(CW$type\fR based on the format of \&\f(CW$precision\fR. If \f(CW$type\fR is \*(L"decimal\*(R", then \f(CW$count\fR will be the number of digits to use. .PP .Vb 1 \& my ($type, $count) = format_of($precision); .Ve .PP Valid formats should be any of the number formats which are used by Perl. Basically, the 'fraction' methods will work for anything (as long as Perl can divide by it), but we would be wasting time if we only want to round to a certain decimal place. .PP Fractional Formats: .PP Anything which does not reduce to a 'multiple of 10'. .PP .Vb 4 \& 0.125 \& 0.00007 \& 2 \& 2.885 .Ve .PP Decimal Formats: .PP Anything which can be expressed as 1.0e. .PP .Vb 2 \& 0.0000001 \& 1.0e-10 .Ve .PP Number-of-Digits (Decimal) Format: .PP Anything which matches the /^d\ed+$/ pattern will be used as a 'digit count'. .PP .Vb 3 \& d0 \& d5 \& d60 # bad idea, but valid .Ve .PP Fake Format: .PP Anything less than zero. .PP .Vb 2 \& -1 \& -0.001 .Ve .SH "Decimal-based rounding" .IX Header "Decimal-based rounding" .Sh "new" .IX Subsection "new" Creates a new decimal-based rounding object. .PP .Vb 1 \& Math::Round::Var::Float->new(precision => 7); .Ve .PP The argument to precision is the number of digits to use in rounding. This is used as part of a \fIsprintf()\fR format. .Sh "round" .IX Subsection "round" .Vb 1 \& $number = $rounder->round($number); .Ve .SH "Fraction-based rounding." .IX Header "Fraction-based rounding." .Sh "new" .IX Subsection "new" .Vb 1 \& Math::Round::Var::Fraction->new(); .Ve .Sh "round" .IX Subsection "round" .Vb 1 \& $number = $rounder->round($number); .Ve .SH "Fake rounding" .IX Header "Fake rounding" This mode doesn't round at all. This is useful when you need user-input to be able to disable rounding without rewriting a lot of code. .Sh "new" .IX Subsection "new" .Vb 1 \& Math::Round::Var::Fake->new(); .Ve .Sh "round" .IX Subsection "round" .Vb 1 \& $fake->round(); .Ve