When I ran this on my Windows XP machine, it produced the output:#sample data set $Day = 0; $Seconds = 35247; $MicroSeconds = 755605; #combine times into one variable $Time = $Day + ($Seconds+$MicroSeconds/1000000)/86400; #write this time to a file open(FILE,"> test.txt"); printf FILE ("%1.20f",$Time); close(FILE); #read that time back in from file open(FILE,"< test.txt"); @FileContents = <FILE>; $FileTime = $FileContents[0]; #calculate diffence from time stored in memory and written to file $Difference = $Time - $FileTime; #print results print "\nFrom Memory: "; printf("%1.20f",$Time); print "\nFromFile : "; printf("%1.20f",$FileTime); print "\nDifference : "; printf("%1.20f",$Difference);
However, when I looked in the "test.txt" file, the number 0.40796013431712963000 was sitting in there. Why is this different from the "FromFile" number? Is there a way to make sure that the number is read exactly as it is from the file? Thanks for the help.From Memory: 0.40796013431712963000 FromFile : 0.40796013431712957000 Difference : 0.00000000000000005551
In reply to losing precision reading numbers from file by iKnowNothing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |