yes modf seems to be the best solution.
thanks to all for your feedback!
anjan

On Tue, Jan 13, 2009 at 7:36 PM, Rob Dixon <rob.di...@gmx.com> wrote:

> ANJAN PURKAYASTHA wrote:
> > Owen wrote:
> >> ANJAN PURKAYASTHA wrote:
> >>>
> >>> I would like to divide a floating point number into its whole and
> >>> fractional parts.
> >>> So,
> >>> ($w, $f)= some_subroutine(12.735)
> >>> assigns 12 to $w and 0.735 to $f.
> >>>
> >>> Any easy perlish way of doing this?
> >>
> >> Someone no doubt will have a one liner, but here is a logical way of
> >> achieving the result
> >>
> >>
> >> #!/usr/bin/perl -w
> >>
> >> use strict;
> >>
> >> my $nr = "12.75";
> >>
> >> my ( $whole, $part ) = ( int($nr), $nr - int($nr) );
> >>
> >> print "$whole   $part\n ";
> >>
> > thanks owen.
> > after some research i was able to answer my own question.
> > solution:
> >
> > use POSIX;
> > $n= 12.735;
> >
> > $w= floor($n); # assigns the value 12 to $n.
> >
> > $f= $n-$w; # this holds the fractional value.
>
> use strict;
> use warnings;
>
> use POSIX qw/modf/;
>
> my $n= 12.735;
>
> my ($part, $whole) = modf $n;
>
> print "$whole   $part\n";
>
>
> HTH,
>
> Rob
>
>


-- 
=============================
anjan purkayastha, phd
bioinformatics analyst
whitehead institute for biomedical research
nine cambridge center
cambridge, ma 02142

purkayas [at] wi [dot] mit [dot] edu
703.740.6939

Reply via email to