The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Float

Posted by Saurabh Ganguly on July 02, 2001 at 3:42 AM

Hi
I am facing a problem in conversion os String to float.So I thought of contacting you .
I have written the following code for conversion from String to float and then limiting to 2 numbers after decimal.

DecimalFormat numformat = new DecimalFormat();
numformat.applyPattern("#00.00");
String tmpqty=numformat.format(Float.parseFloat(String);
totalQty=totalQty+Float.parseFloat(tmpqty);

totalQty is a float quantity.
But what happens is that I am not getting exact results.I mean if the result is .756 then its coming as .76.
SO I want a solution cos it can lead to calculation differences.
Hoping for a positive reply.
Cheers
Saurabh





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us