Fixed-point format for floating-point numbers

M

Motaz Saad

Dear All,
Please how can I fix the significant places (number of digits after the
float point) for the floating-point numbers in java?
Thanks In Advance.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Motaz Khalid Saad.
Department Of Computer Science
Information Technology College
Islamic University - Gaza - Palestine
http://www.iugaza.edu.ps
http://www.geocities.com/motsad
e-mail: (e-mail address removed) , (e-mail address removed)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
T

Tim Slattery

Motaz Saad said:
Dear All,
Please how can I fix the significant places (number of digits after the
float point) for the floating-point numbers in java?
Thanks In Advance.

You can't, that's why they are called floating point numbers.

If you need to do fixed point arithmetic, look at the BigDecimal
class.
 
T

Tex

Please how can I fix the significant places (number of digits after the
float point) for the floating-point numbers in java?
Thanks In Advance.

Floating point in any language and on any hardware is not suitable for
fixing significant digits. This question frequently comes up for science
& engineering wherein there are rules for the number of significant
digits you should allow for computations, i.e. how accurate your can
express your results.

Floating point does not contain all decimal fractions, e.g. 0.10 does not
exist in floating point. A close binary representation (< 0.10) will be
stored.
It is kinda like s = 1/3 actually stores 0.333333 so 1/3 is not stored. So
when you enter an arbitrary fractional number, say d = 32.5694, that
number may well not exist, so only an approximation is stored, and
similarly for interiem computational results.

Mostly results are close enough for engineering & gov't work to just
round and convert to a string for people. When exact control of precision
is required you need to work in integer arithmetic, i.e. many financial
calculations are done in 1/100 of a cent, because banks don't want to
lose or gain pennies every now and then, which would result if they used
floating point to keep our bank records. Physics frequently requires
great precision and control of significant results and thus integer
arithmetic. To a mathematician, floating point doesn't work at all.

You can get (free) math packages to handle very large numbers of
significant digits if your numbers cannot be handled by standard
integers.

--tex
 
T

Tim Slattery

Floating point does not contain all decimal fractions, e.g. 0.10 does not
exist in floating point. A close binary representation (< 0.10) will be
stored.

<NITPICK>
Yes, but that's not because it's "floating point", it's because it's
*binary* floating point.
</NITPICK>
 
J

Joan

Tim Slattery said:
<NITPICK>
Yes, but that's not because it's "floating point", it's because
it's
*binary* floating point.
</NITPICK>
I think it is interesting that I wrote a JNI program in C that
returns the
number of bytes on a MS Windows machine hard drive as a float.
(And it works.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top