How about

#!/usr/bin/perl -w
use strict;
my $number = 10.25233006477356 ;
my $truncatedNumber = sprintf("%10.6f", $number) ;
print $truncatedNumber ;


Result: 10.252330

Keeping in mind that %10.6f is the format for a floating point number with 9 
digits and the decimal point or a total of 10. If you number could contain more 
than three digits to the left of the decimal point you would have to increase 
10 to some larger number.

Bill
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brian Rowlands 
(Greymouth High School)
Sent: Tuesday, June 19, 2007 10:18 PM
To: [email protected]
Cc: John Townsend
Subject: RE: Truncating decimal number

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Townsend
Sent: Wednesday, 20 June 2007 10:50 a.m.
To: [email protected]
Cc: Chad Freeman
Subject: Truncating decimal number

I'm trying to truncate a number, 10.25233006477356, to 6 decimal points. E.g. 
10.252330.

I don't need to round the number, I just want it to drop everything after the 
6th decimal point. This should be easy, but I'm drawing a blank.

Thanks

Working with strings is probably the most natural way. Convert to a string and 
peel off the string as far as the 6th DP as people are suggesting. However, 
mathematically speaking, subtracting 0.000 000 5 from the number and then 
rounding should work exactly the same.

Hope that helps



Brian Rowlands




_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to