-----BEGIN PGP SIGNED MESSAGE-----

Moin,

sorry for respondint so late, I don't read that list.

>Gibbs Tanton writes:
>>  You might want to try Math::BigFloat instead.
>
>I originally wrote:
>> I'm trying to perform the following calculation:
>> $value = ($float + $integer) * 100000;
>> $string = "$value:test";
>
>I now have code like the following:
>use Math::BigFloat;
>
># Initial values
>my $float   = 1000123123.12345;
>my $integer = 123456789;

This will go wrong, you need to protect the values with "", otherwise Perl
will sneak in, interpret them as numbers and store them in a limited
scalar, thus throwing away some resolution.

>my $factor  = 1000000;
>my $string  = ":test";
>my $value;
>
>$value = Math::BigFloat->new($float);
>print "Value 1: $value.\n";

Fine so far ;)

>$value = Math::BigFloat->new($value->fadd($integer));
>print "Value 2: $value.\n";

You can write shorter:

$value += $integer;

>$value = Math::BigFloat->new($value->fmul($factor));
>print "Value 3: $value.\n";

Ditto here:

$value *= $factor;

>$value =~ s/.$//;  # Remove decimal point
>print "Value 4: $value.\n";

Fine, but remember that the result is a bare string, not an object.

>$value .= $string; # Append string
>print "Value 5: $value.\n";

>This outputs:
>Value 1: 1000123123.12345.
>Value 2: 1123579912.12345.
>Value 3: 1123579912123450..
>Value 4: 1123579912123450.
>Value 5: 1123579912123450:test.

Look quite good to me ;)

And in case you have an old version of Math::BigInt/BigFloat, go to
search.cpan.org and enter "Math::BigInt" into the box, you will be able to
get an updated version there.

To check the version do this:

perl -MMath::BigInt -e 'print $Math::BigInt::VERSION,"\n"'

Current is v1.45.

Thanx for your interest.

Tels

- -- 
perl -MMath::String -e 'print \
Math::String->from_number("215960156869840440586892398248"),"\n"'

 http://bloodgate.com/perl       My current Perl projects
 PGP key available on http://bloodgate.com/tels.asc or via email.


-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: latin1

iQEVAwUBO/Kt7XcLPEOTuEwVAQHi+wf9HuGi/hfdTYzOy+RfeowHiLXLKorjfNeb
uld8NE2+N8tYtDChFRjRwSlSAx13T3l3Ow2Y2IN9TKX9BViLNvd/l2crKtVAiZdK
HINj7YdfJl29NoHVtSDjF73e0GE7R6PRow707az0Xuv50vmQINA8i7QpAag/1/AT
FSe3y8R7ZLNW0Qv5l1v7cLVNpGMq0s7NBRncZ3OR2NjrQdYfQXTnyHPbHT8DKz1r
7ri3iV3hKxlSYK7+QJqIALNUikdpkn7s4b0ajYMyOYcwtnZYT+EyHlQQfkhA/QjD
EiJ78G2/R5lVUDqMPHWG5EnaHWXC+NZio0mIflu5UmIn4UegCIZX7w==
=9bua
-----END PGP SIGNATURE-----

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to