http://qs321.pair.com?node_id=11123131


in reply to Re: int() function
in thread int() function

Minor correction: in OP's code, it's not Perl's print() function that is rounding the floating point value up to 196. It's happening on string interpolation.

Replies are listed 'Best First'.
Re^3: int() function
by LanX (Saint) on Oct 24, 2020 at 20:36 UTC
    I think it's anything which does a stringification.

    DB<137> $x1 = (1.15*170)+0.50; DB<138> p "$x1" 196 DB<139> p $x1 196 DB<140> printf "%.20f\n",$x1 195.99999999999997000000 DB<141> $str = $x1."" DB<142> p length $str 3 DB<143>

    yep!

    DB<151> $x2 = (1.15*170)+0.50; DB<152> Dump $x2 SV = NV(0x32cc698) at 0x32cc6b0 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 196 DB<153> p $x2 196 DB<154> Dump $x2 SV = PVNV(0x1cb938) at 0x32cc6b0 REFCNT = 1 FLAGS = (NOK,pNOK) IV = 0 NV = 196 PV = 0x31a4748 "196"\0 CUR = 3 LEN = 32

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery