## When bigdecimal and when just double ??

### When bigdecimal and when just double ??

Hy,
I need to do simple multiply,
for example 58 multiply by a double 1,4536366 .
The result is different respect to what I've with windows calculator.
Using BigDecimal the program becames too slow so I need to know when I
could use just double to make a multiply, or a add , or a subtract, or
a divide.
Thanks

Antonio
www.etantonio.it/en

### When bigdecimal and when just double ??

In article
< XXXX@XXXXX.COM >,

[...]

Why don't you write a short example showing the result you get and the
result you expected:

< http://www.yqcomputer.com/ ;

Here's a helpful article on the topic:

< http://www.yqcomputer.com/ ;

--
John B. Matthews
trashgod at gmail dot com
< http://www.yqcomputer.com/ ;

### When bigdecimal and when just double ??

...

What is the purpose of the multiply? The choice of BigDecimal vs. double
depends on big picture issues.

For example, in some contexts exactness, or failing that controlled
rounding, is particularly important for numbers that have exact decimal
representations. Think about accounting. That is where BigDecimal is
really needed.

Double is a binary fraction system, so decimal fractions have no special
status. 1.4536366 can only be approximated in double, not represented
exactly. However, numbers can be approximated to over 15 decimal digits,
good enough for a lot of engineering and scientific calculations. It is
a very compact representation, supported in hardware on many processors,
making it extremely efficient.

Patricia

### When bigdecimal and when just double ??

...
...

It is certainly not "in error" because it is acting in accordance with
its published behavior: "Extended Precision, a feature of Calculator,
means that all operations are accurate to at least 32 digits. Calculator
also stores rational numbers as fractions to retain accuracy. For
example, 1/3 is stored as 1/3, rather than .333." (Windows XP Calculator
Help - calculations - extended precision).

It is no more in error than is BigDecimal for producing a different
answer from IEEE 754 64 bit binary. Both are supposed, according to
their specifications, to produce the infinitely precise result for that
case, and both do so.

Computer arithmetic often involves trade-offs between various desirable
properties, such as range, accuracy for particular cases, automatic
scaling, performance, and compactness. Two programs with different
criteria, and different specifications, can produce different results
for the same calculation without either of them being "in error".

Patricia

### When bigdecimal and when just double ??

On Thu, 19 Feb 2009 03:14:44 -0800 (PST), etantonio
< XXXX@XXXXX.COM > wrote, quoted or indirectly quoted someone
who said :

If you want a precise answer use int or long.

If the answer is too fat to fit in a long use BigInteger or BigDecimal

If the answer is a measurement of a physical quantity, use a double or
float depending on the accuracy required. It equivalent to scientific
notation, allowing very large or very small numbers with only about 15
significant digits.

See http://www.yqcomputer.com/
various types.

in your particular case 58 * 1,4536366 = 843,109,228

The biggest possible int is 2,147,483,647, so you can handle this with
ordinary ints.

--
Roedy Green Canadian Mind Products
http://www.yqcomputer.com/

One path leads to despair and utter hopelessness. The other,
to total extinction. Let us pray we have the wisdom to choose correctly.
~ Woody Allen .

### When bigdecimal and when just double ??

etantonio wrote, quoted or indirectly quoted someone

Given the ".it" suffix on the email address, it is likely that the OP was
using the comma as the radix point, making the answer slightly larger than 84.
It is highly unlikely that the answer would have diverged from that given by
the Windows calculator otherwise.

--
Lew

### When bigdecimal and when just double ??

Actually Java only complies to its own standards, and not IEEE
754/854.