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
0 answers

Bigdecimal values are not properly inserted with Spring 'BatchSqlUpdate' class

I have an application which reads data from excel and write it into Oracle DB using Spring BatchSqlUpdate class. The values are getting properly inserted for most of the cases but for some rare cases i am getting below issues. In Spring sql types…
0
votes
2 answers

Big Decimal numbers subtraction is not working

I am facing simple issue in below program. In below code I am just subtracting numbers and expected output is "89.50" but it is printing 90. May I know the reason and help me with code to get expected output. public class BigDecimal_Prb { public…
Raghu
  • 59
  • 3
  • 17
0
votes
1 answer

How to get from 10.0/3*3 BigDecimal and double?

double a = 10.0; double b =3; double c = a/b; System.out.println(c*b);//answer = 10.0 BigDecimal bigDecimal1 = BigDecimal.valueOf(c); BigDecimal bigDecimal2 = new BigDecimal("3"); System.out.println(bigDecimal1.multiply(bigDecimal2));//answer =…
WeFUN
  • 1
  • 2
0
votes
1 answer

BigDecimal output with correct format

Please help me to set output of BigDecimal. For example: I need to output numbers which have a length that is less than 8 digits like this: "12345678", and if more then: "1,2345Е+9". Methods toPlainString(); toEngineeringString(); toString(); are…
Bitlejuce Do
  • 163
  • 3
  • 14
0
votes
0 answers

Java BigDecimal setScale used with RoundingMode.CEILING

I have created the following helper function for rounding decimals: public static double round(double value, int places, RoundingMode roundingMode) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = new…
trajan
  • 416
  • 1
  • 4
  • 10
0
votes
0 answers

Jackson remove "e" from BigDecimal

I have a low decimal value: 2e-8 I want it to be presented as JSON in the format 0.00000002 Tried to create a JsonSerializer and use BigDecimal method "toPlainString" but it is not good for me because the JSON has to show a number and not a string…
Ido Barash
  • 4,856
  • 11
  • 41
  • 78
0
votes
1 answer

BigDecimal - how to do this calculation in Java

I have .. target = targetmax / difficulty targetmax = 26959535291011309493156476344723991336010898738574164086137773096960 difficulty = 14484.162361 target = 26959535291011309493156476344723991336010898738574164086137773096960 / 14484.162361 target…
Jagdish
  • 231
  • 4
  • 18
0
votes
1 answer

Best way to check minor unit of BigDecimal in Java

I have a minor unit setup for amounts, which is: 0.01 It means the amounts are allowed to have maximum 2 decimals. What could be the best and easiest validation check in Java for these examples: 5 --> valid 5.0 --> valid 5.00 --> valid 5.000 -->…
victorio
  • 6,224
  • 24
  • 77
  • 113
0
votes
1 answer

Deserialize BigDecimal in scala with json4s return empty list

Given this json: { "id": "1", "details": [{ "tax": [{ "amount": 1 }, { "amount": 2 }] }] } I'm trying to reading it in this way: lazy val amounts: List[BigDecimal] = parse(json) \\…
Giulio Caccin
  • 2,962
  • 6
  • 36
  • 57
0
votes
0 answers

BigDecimal.doubleValue() somehow yielded an incorrect result

I have a class (let's call it Money) that handles calculation of monetary values. It's a wrapper for BigDecimal and uses the correct decimal precision for money. It has worked pretty well for many years, but we have had an incident that had some…
Xenno
  • 46
  • 2
0
votes
1 answer

Java division using BigDecimal

I am a newbie on java so I need your help on a project I am working on! I defined some counters, these are what will I use: int[] acceptCounters = {}; int[] acceptFailCounters = {}; Then I wrote them like that to get connection with database, and…
frusciante
  • 11
  • 1
  • 3
0
votes
1 answer

Handle decimal entered as whole number Rails

I'm fairly new to rails and having a problem that I'm sure is not unique, but can't seem to find an elegant solution to on my own: I have a model with a :tax_rate decimal attribute that is used to create a total later on using some multiplication in…
PSCampbell
  • 858
  • 9
  • 27
0
votes
2 answers

Observations with Round-ing in Android Studio - java. And some practical explanations expected

In Android Studio I had problems with calculating invoice totals because of the way java rounds. I know there are a lot of explanations, but many recommend methods that don't return reliable results. For example: 1. Math.round((double)4.715 *…
mihai71
  • 347
  • 4
  • 9
0
votes
1 answer

C++ type with 200 digits after decimal point?

I have a project for my school, and the goal of it is create simple "Virtual Machine" who execute operations. To do that, we can store some numbers with types, they are: int8, int16, int32, float, double, and big decimal. The only type i don't know…
Jean Walrave
  • 191
  • 1
  • 2
  • 13
0
votes
2 answers

Converting BigDecimal.toPlainString() to double for performing arithmetic operations

I am getting the following value from my database when I do resultSet.getdouble() 2.0006362409E9 I want to perform arithmetic operations on this number. I tried to get the actual value using BigDecimal.toPlainString(), then I am getting the…
Shivkumar Mallesappa
  • 2,875
  • 7
  • 41
  • 68