AlienSpaces has asked for the wisdom of the Perl Monks concerning the following question:
Would love to know the best way to handle numbers with precision in Perl. These numbers (ie: strings) may come from anywhere such as a database, a spread sheet etc What is the best way to clean them, add them, multiply them with confidence? :) Thanks in advance.my $a = 000.76; my $b = 4; my $c = $a * $b; print $c; 304 my $a = .76; my $b = 4; my $c = $a * $b; print $c; 3.04 my $a = 0.76; my $b = 4; my $c = $a * $b; print $c; 3.04 my $a = 0000.76; my $b = 4; my $c = $a * $b; print $c; 304 my $a = 0000.76 + 0; my $b = 4; my $c = $a * $b; print $c; 304 my $a = .76; my $b = 4; my $c = $a * $b; print $c; 3.04 my $a = "000.76"; my $b = 4; my $c = $a * $b; print $c; 3.04
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl with precision
by BrowserUk (Patriarch) on Feb 28, 2012 at 23:52 UTC | |
by tye (Sage) on Feb 29, 2012 at 00:04 UTC | |
by lidden (Curate) on Feb 29, 2012 at 00:56 UTC | |
by Marshall (Canon) on Feb 29, 2012 at 00:28 UTC | |
by BrowserUk (Patriarch) on Feb 29, 2012 at 00:38 UTC | |
by AlienSpaces (Initiate) on Feb 29, 2012 at 02:01 UTC | |
by BrowserUk (Patriarch) on Feb 29, 2012 at 03:45 UTC | |
by Marshall (Canon) on Feb 29, 2012 at 07:26 UTC | |
by AnomalousMonk (Archbishop) on Feb 29, 2012 at 02:31 UTC | |
by Marshall (Canon) on Feb 29, 2012 at 00:56 UTC | |
|
Re: Perl with precision (strings!)
by tye (Sage) on Feb 28, 2012 at 23:46 UTC | |
|
Re: Perl with precision
by Anonymous Monk on Feb 28, 2012 at 23:52 UTC | |
by Anonymous Monk on Feb 29, 2012 at 00:07 UTC | |
by Anonymous Monk on Feb 29, 2012 at 00:58 UTC | |
by AnomalousMonk (Archbishop) on Feb 29, 2012 at 01:51 UTC | |
by Anonymous Monk on Feb 29, 2012 at 02:14 UTC | |
| |
by Anonymous Monk on Feb 29, 2012 at 14:09 UTC |