in reply to Re^3: Coping with decimals
in thread Coping with decimals
Having a mental map that considers strings numbers and numbers strings allows one to make subtle errors in their programs.
In fact, sprintf returns a string after doing an arithmatic operation. Compare a 2 deciaml point operation via sprintf:
my $num = 4.62899; $round = sprintf "%.2f", $num; print "$round\n";
For another example consider this snip and output.
my $string = "0.0"; print "string $string is ", ($string ? "True" : "False"), "\n"; print "string $string is ", ($string+0 ? "True" : "False"), "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Coping with decimals
by tlm (Prior) on Jun 02, 2005 at 16:47 UTC |