in reply to Re^3: All Calculations Done with One Variable Give Integer Answers
in thread All Calculations Done with One Variable Give Integer Answers

Interesting, slightly older Perl here and it does exactly what the OP indicates. Whether or not it accomplishes what he wants to accomplish is a different subject.

I am baffled that anything would autonomously constrain itself to integer arithmetic -- I think we need to see some code to really assess what is going on.

Update: As a complete side note, the version of Perl doesn't appear to cause a difference in the handling of the string interpretation. I suspect the difference between ww's results and mine are how we chose to display the values (either say vs. print, or command line vs. script file {perhaps the way the quotation mark characters are interpreted from the command line?} ):

#!/usr/bin/perl -w use strict; { my $originalValue = 5; my $modifiedValue = "$originalValue.00"; my $escapedValue = "$originalValue\.00"; print "\$originalvalue = '$originalValue'\n"; print "\$modifiedvalue = '$modifiedValue'\n"; print "\$escapedvalue = '$escapedValue'\n"; } exit; __END__ ---------------[ Older Perl ]--------------- C:\Steve\Dev\PerlMonks\P-2013-09-23@1207-ForceFloat>perl -v This is perl, v5.8.9 built for MSWin32-x64-multi-thread (with 12 registered patches, see perl -V for more detail) C:\Steve\Dev\PerlMonks\P-2013-09-23@1207-ForceFloat>forcefloat.pl $originalvalue = '5' $modifiedvalue = '5.00' $escapedvalue = '5.00' ---------------[ Newer Perl ]--------------- C:\Steve\Dev\PerlMonks\P-2013-09-23@1207-ForceFloat>perl -v This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x +64-multi-thread (with 1 registered patch, see perl -V for more detail) C:\Steve\Dev\PerlMonks\P-2013-09-23@1207-ForceFloat>forcefloat.pl $originalvalue = '5' $modifiedvalue = '5.00' $escapedvalue = '5.00'
  • Comment on Re^4: All Calculations Done with One Variable Give Integer Answers
  • Download Code

Replies are listed 'Best First'.
Re^5: All Calculations Done with One Variable Give Integer Answers
by HalNineThousand (Beadle) on Sep 23, 2013 at 23:27 UTC
    I think I've found the culprit, but I will be providing code this evening (USA East Coast time). This is part of a big project (bookkeeping, not programming) that I'm on a deadline on. I put together a sloppy and quick test program I'll tidy up for posting here. It seems the issue is one module used Math::BigInt. I'll include new information when I add the code tonight.
      Good sleuthing -- I am highly intrigued by this so I wait with bated breath for your test sample. Wanna learn wanna learn wanna learn!
        I am highly intrigued by this

        Most likely it's standard Math::BigInt behaviour and standard Perl behaviour:
        use strict; use warnings; use Math::BigInt; my $x = Math::BigInt->new(17); my $y = 70 / $x; print $y, "\n"; $x = "$x.00"; #or: #$x = "$x"; $y = 70 / $x; print $y, "\n"; __END__ Outputs: 4 4.11764705882353
        Cheers,
        Rob
        New code is up in the main post. I want to understand what's going on as well. But I have to admit, since I'm under crunch time, I also am eager for an answer for practical reasons, too! (I really want to get this fixed so I can get a good night's sleep!)