The float/double type have a representation truth hidden in them, its time you learnt of that ;)
This should help: http://www.lahey.com/float.htm If you need such an accuracy, consider using BigDecimal or other such libraries. Another good article (from the Python folks) is: http://docs.python.org/tutorial/floatingpoint.html [This isn't a pig issue, its the way float/double are implemented in Java, as per the IEEE 754] On Thu, Jul 22, 2010 at 6:49 PM, Rohan Rai <[email protected]> wrote: > Strangest thing > > public class Test1 { > > public static void main(String[] args) throws Exception{ > > System.out.println(new Double(new Double(3) * new Double(0.006))); > > } > > } > > Also gives output as 0.018000000000000002 > > Regards > Rohan > > Rohan Rai wrote: >> >> Hi >> >> INFRA == pig 0.6 OVER hadoop 0.20.2 >> >> Here is the scenario >> >> >> A = LOAD 'file:///home/hadoop/a' using PigStorage(',') AS >> (c1:int,c2:double); >> DUMP A >> >> (2,0.0060) >> (3,0.0050) >> (3,0.0060) >> B = FOREACH A GENERATE c1*c2; >> >> >> (0.012) >> (0.015) >> (0.018000000000000002) >> >> WHAT does *(0.018000000000000002) *signify. Why is it not giving *0.0180* >> >> Regards >> Rohan >> >> The information contained in this communication is intended solely for the >> use of the individual or entity to whom it is addressed and others >> authorized to receive it. It may contain confidential or legally privileged >> information. If you are not the intended recipient you are hereby notified >> that any disclosure, copying, distribution or taking any action in reliance >> on the contents of this information is strictly prohibited and may be >> unlawful. If you have received this communication in error, please notify us >> immediately by responding to this email and then delete it from your system. >> The firm is neither liable for the proper and complete transmission of the >> information contained in this communication nor for any delay in its >> receipt. >> >> > > > The information contained in this communication is intended solely for the > use of the individual or entity to whom it is addressed and others > authorized to receive it. It may contain confidential or legally privileged > information. If you are not the intended recipient you are hereby notified > that any disclosure, copying, distribution or taking any action in reliance > on the contents of this information is strictly prohibited and may be > unlawful. If you have received this communication in error, please notify us > immediately by responding to this email and then delete it from your system. > The firm is neither liable for the proper and complete transmission of the > information contained in this communication nor for any delay in its > receipt. > -- Harsh J www.harshj.com
