Floating point precision
Hello
I have a string in the format 41.821874591 -88.273521.
now I want to save the two float values for which I use
st = new StringTokenizer("41.821874591 -88.273521"," ");
float floatnum = new Float(st.nextToken());
when I print floatnum I get 41.821873 I loose 3 places of precision.
I tried DecimalFormat but it only returns String data.
How can I retain the 3 places of decimal?
[439 byte] By [
araoa] at [2007-11-27 9:49:56]

it is not matter how many decimal it can hold, but how precise...Float is single precision, while double is double precision... to read upon single and double go: http://en.wikipedia.org/wiki/Single_precision http://en.wikipedia.org/wiki/Double_precision
> And anyway, unless you have a compelling reason,> prefer double over float.And if double's still not enough, use a BigDecimal, which gives (pratically) infinite precision, but is more complicated to use.
> > And anyway, unless you have a compelling reason,
> > prefer double over float.
>
> And if double's still not enough, use a BigDecimal,
> which gives (pratically) infinite precision, but is
> more complicated to use.
BigDaddy thinks BigDecimal is big-diggity
> I have compelling reasons to work with float
Now you've got my curiosity up. What are these compelling reasons?
> My question is can't a number say 11.123456789
> be stored as a float if not what is the maximum
> places of decimal a float can represent?
Read the links supplied in reply 6 to answer this question.
Message was edited by:
petes1234
Ha Ha, I have submitted the data schemas to the client and they are expecting it as float data type. I can only change it, if it is impossible to use float here.
araoa at 2007-7-13 0:18:30 >

> when I print floatnum I get 41.821873
When you print it how? The truncation is probably happening when you print, not in the value itself. OTHO there are only 24 bits of precision in a float.
> I have submitted the data schemas to the client
In that case you have made a bad mistake. You should have established the capacity and the feasibility of using that format before getting the client to sign it off.
ejpa at 2007-7-13 0:18:30 >
