baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
i need help with "rounding" the numbers. example:
will produce :use strict; use bignum; my $e = 0.00141; my $o =1; for(my $r=0; $r<=10; $r++){ $o *=$e; print "$o\n"; }
well the problem is that i would like to deal with only max 5 numbers after the last zero in the decimal number. meaning if the number is : 0.00000000000000000000000000003105926159393528563401 than i vould like to take the number0.00141 0.0000019881 0.000000002803221 0.00000000000395254161 0.0000000000000055730836701 0.000000000000000007858047974841 0.00000000000000000001107984764452581 0.0000000000000000000000156225851787813921 0.000000000000000000000000022027845102081762861 0.00000000000000000000000000003105926159393528563401 0.0000000000000000000000000000000437935588474487527439541
rounding the last digit (9 to 10 ->0 ; 31060) if the number after the 9 is 8 but if it is 1 or 2 like the example than 9 stays. and than deal with that number when calculating the next number in the iteration (last number in the list)0.000000000000000000000000000031059
thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: decimal precision
by psini (Deacon) on May 30, 2008 at 10:56 UTC | |
|
Re: decimal precision
by GrandFather (Saint) on May 30, 2008 at 11:12 UTC | |
by almut (Canon) on May 30, 2008 at 11:44 UTC | |
|
Re: decimal precision
by why_bird (Pilgrim) on May 30, 2008 at 15:08 UTC |