in reply to Dividing and format

I frankly don't understand why you should have an internal representation of the number with the decimal zero (either you want to print it or you want to compute with it, but maybe I'm wrong). Anyway the right way to go is using sprintf() to generate a correctly truncated string and then rely on Perl's ability to cast numbers in the most appropriate ways.

Here is an example:

use strict; while ( <DATA> ) { my $val = sprintf( "%.01f", $_/1000 ); # do maths with the truncated result.... my $val2 = $val * 2; print "$val - $val2\n"; } __DATA__ 100 1000 2314 171 123456789
The result is
0.1 - 0.2
1.0 - 2
2.3 - 4.6
0.2 - 0.4
123456.8 - 246913.6
Note how the .0 is lost if you do any maths on 1.0 unless you format it again before printing - the first column is made of strings, the second of floats.