Questions tagged [bigdecimal]

BigDecimal is a numeric object type in Java that represents decimal numbers with arbitrary precision.

Because double and float use a fixed amount of memory (64 and 32 bits respectively), they have limited precision which can lead to rounding errors, and more importantly, they cannot be used to represent all decimal fractions exactly as they use two's complement.

BigDecimal solves these problems by providing arbitrary precision and by using a decimal representation of their values.

The BigDecimal class also provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.

More information can be found in the BigDecimal Javadoc

1677 questions
0
votes
1 answer

java convert from double/bigDecimal/float to string with 4decimals approximation

I need precision math of maximum 4 decimals that need to be converted to string in order to proceed further with the result in my code and in case the result has more that 4decimals I would like to get the result approximation. Ex: for 3.3333333333…
Sanity
  • 3
  • 2
0
votes
2 answers

How is BigDecimal represented in the JavaScript compiled by GWT

In GWT one can use java.math.BigDecimal in the client code. How are these BigDecimals represented in the resulting JavaScript code after compilation? Is there some extra class for that or do they use a native JavaScript object?
Sebastian
  • 5,721
  • 3
  • 43
  • 69
0
votes
0 answers

Java unmarshaller not parsing simple type being a decimal, with regex rules defined

I'm having problem with java unmarshaller. Whole code was built based on an xsd fedinition. There I have decimal type defined as follows:
0
votes
1 answer

Dividing two ints into a big decimal

I'm conducting an experiment in which we will occasionally have to divide small numbers by large numbers, for example: 4 / 90,000. Using a double results in a 4.444444444e. I was hoping perhaps a BigDecimal could handle this arithmetic and give me a…
Talen Kylon
  • 1,908
  • 7
  • 32
  • 60
0
votes
1 answer

Why is BigDecimal's scale not a BigInteger?

Why is the scale field of a BigDecimal not a BigInteger? I assume currently it makes maybe no sense because calculations with that many decimal places are likely never performed, but wouldn't it make sense for the future to rather use a BigInteger?
Marcono1234
  • 5,856
  • 1
  • 25
  • 43
0
votes
1 answer

Convert Bigdecimal to Timeformat for a string

Basically, I'm using app42 to store scores for a game. However my game uses times. For example. If I submit a score of 0:3:85 ( 0 hours, 3 seconds and 85 milliseconds) it would be stored as a bigdecimal as 385. When i retrieve my score I retrieve it…
Rhys Drury
  • 305
  • 2
  • 20
0
votes
2 answers

Iterating over a hashMap key changes to BigDecimal

My issue is this, I have hashMap //for (String tablaBuscar : listaTablas) { // RECUPERAR REGISTROS POR TABLA HashMap listaRegistros =(HashMap) RequerimientosTablaDestino …
0
votes
1 answer

java.math.BigDecimal comparison: the same value represented in different formats don't match

The following code: BigDecimal a = new BigDecimal("8900"); BigDecimal b = new BigDecimal("8.9E+3"); System.out.println(a.equals(b)); prints false. Why is so, if mathematically those numbers are equal?
Denis Kulagin
  • 8,472
  • 17
  • 60
  • 129
0
votes
0 answers

What is the worst approximation error occurring using Java float to represent amounts of money?

I'm managing a piece of legacy code that uses float variables to manages amount of money and this cause some approximation issue. I know that this is not the correct way to represent money and that should be used the BigDecimal type but the…
user2572526
  • 1,219
  • 2
  • 17
  • 35
0
votes
0 answers

can't multiply a double by a BigDecimal

public BigDecimal calcularPrecioEnDolares(BigDecimal precio) { return precioEnDolares = precio.multiply(BigDecimal.valueOf(1.14)); } public String toString() { return "El piso con número de referencia " + this.numeroDeReferencia + ", " +…
0
votes
0 answers

BigDecimal java - precision bigger then provided value - how to fill with zeros

I would like to control the exact value of a BigDecimal. with: BigDecimal b=new BigDecimal(2.503); I got 2.5030069968686868... how to set up this overflow scale numbers to 0? I want to get: 2.503000000000000..0 I was trying with setScale without…
Aga
  • 179
  • 1
  • 9
0
votes
1 answer

Issue with subtract in Bigdecimal

Hi there this operation give me undesired response , how i can get desired response from it ? For example when a and second is equal : a=a.subtract(second); a=0.99999905050206647416680425521917641162872314453125 second=1.0 give me…
Michael Ghorb
  • 359
  • 4
  • 12
0
votes
2 answers

Java - Modulus function fails on large numbers

I am working on RSA algo but the numbers, on which different operations are performed, are very large. And Java operators are failing here. I need to take modulus of a very large number (like this big 1.35858791876006E+75) but the normal % or…
Bugs Happen
  • 2,169
  • 4
  • 33
  • 59
0
votes
2 answers

Big decimal Conversion with roundup value

i have a double value Such as Double doubleValue=0.0001; trying to print this gave me an output as 1.0E-4 So I tried BigDecimal to value of this as. BigDecimal.valueOf(doubleValue) which ended up giving output as "0.00010". can anyone let me know…
Kumar
  • 183
  • 1
  • 12
0
votes
0 answers

How do I coerce Ruby's BigDecimal::round to give me more precision?

I'm working on Project Euler's problem 26, which involves finding repetitions in the decimal place when I do division such as 1/6, 1/7, 1/8 etc. I'm having a hard time getting BigDecimal to give enough precision to find long patterns of repetition.…
mikeappell
  • 363
  • 4
  • 17