Well I seem to have solved the print problem with print 'crt solution =', $crt1 -> bdstr(),"\n";
You can just as well use
print $crt1, "\n"; or
say $crt1;.
But
printf "%.0f\n", $crt1; will simply round the value 954846259588805228035541587771 to a double:
use warnings;
use strict;
use Math::BigFloat;
use feature ':5.10';
my $x = Math::BigFloat->new('954846259588805228035541587771');
print $x->bdstr(), "\n";
print $x, "\n";
say $x;
printf "%.0f\n", $x;
printf "%.29e\n", 954846259588805228035541587771;
__END__
Outputs:
954846259588805228035541587771
954846259588805228035541587771
954846259588805228035541587771
954846259588805282215996948480
9.54846259588805282215996948480e+29
You get the correct output using "print" and "say" owing to operator overloading, and because $crt1 is a Math::BigFloat object.
Similarly, it doesn't matter whether you multiply/divide/add/subtract $crt1 with an integer, a perl floating point value, another Math::BigFloat object, or even a string.
This, again, can be attributed to operator overloading:
use warnings;
use strict;
use Math::BigFloat;
use feature ':5.10';
my $x = Math::BigFloat->new('954846259588805228035541587771');
print $x * 2, "\n";
print $x * 2.5, "\n";
print $x * Math::BigFloat->new('2.5'), "\n";
print $x * "2.5";
__END__
Outputs:
1909692519177610456071083175542
2387115648972013070088853969427.5
2387115648972013070088853969427.5
2387115648972013070088853969427.5
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.