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

Number becomes to BigDecimal after the hibernate reverse engeering?

I set the field as Number like below in the oracle database.       name             type    length      scale EMP_GENDER NUMBER   0             0 After the hibernate reverse engineering,this filed's type becomes to BigDecimal. private…
Brutal_JL
  • 2,839
  • 2
  • 21
  • 27
0
votes
1 answer

What is the best way to format a big decimal into dollar form?

I have an ugly print method that takes a long regex as a String. There has to be a simpler solution. // output is in dollars String formatString = "%1$-20d%2$-20.2f%3$-20.2f%4$.2f,%5$.2f,%6$.2f\n"; printf(formatString, paymentNumber++,…
user10297
  • 139
  • 4
  • 11
0
votes
0 answers

Putting fixed rounding in MathContext

I was trying to add some more code in the following MathContext private static MathContext mc = new MathContext( 12, RoundingMode.HALF_EVEN ); This is the code I was trying to put in the context footToMeter =…
0
votes
1 answer

How do you use BigDecimal correctly for variables?

I have been working on a small program, in it you press a button and it adds .1 to a variable. I've been using a double and I keep getting super long decimals(such as 12.0000000000000001). After googling the issue I came up with the BigDecimal…
Tdude179
  • 29
  • 4
0
votes
3 answers

Why 1 divided by 1.1 doesn't work, even when I'm using BigDecimal in my code?

I'm trying to do a calculator with the 4 basic operations. I started using doubles to get the arguments from edittext, but I discovered the problem with decimal values. To avoid that, I used BigDecimal, but now the app is failing at some specific…
rado
  • 5,720
  • 5
  • 29
  • 51
0
votes
1 answer

Converting a decimal number to full integer - is BigDecimal overkill?

I'd like to convert miles to kilometers. Is usage of BigDecimal an overkill in this situation? Could I improved the following not using BigDecimals? I'd like to round to the nearest full number. I'm not interested in the decimal fractions. private…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
0
votes
2 answers

Is it not possible to store BigDecimal values in a single-dimensional array

My goal is store BigDecimal values as I input them through the Scanner class. I want to store BigDecimal numbers into an array so that I can sort them numerically. Can this be done using a single-dimensional array? I can't find any BigInteger…
poetryrocksalot
  • 697
  • 2
  • 10
  • 19
0
votes
1 answer

How to check if a number is not within 50 decimal places of square root of two?

I understand that double might not be precise enough. However, I couldn't find a way to do so using BigDecimal. I tried while(Math.log10(Math.abs(a.subtract(new BigDecimal(1.41421356237309504880168872420969807856967187537694))) >= -50 ||…
0
votes
1 answer

multiple while loop comparison (BigDecimal and > 10 )

This is my first post and I have been searching google and stack overflow for the past 24 hours and can not seem to pin down my problem. I am creating a simple square root program. For the input section I start a 'while' loop. I need it to compare…
Mikeb530
  • 15
  • 4
0
votes
0 answers

How to divide a BigDecimal and get the same value after sum these values

I need to divide a financial value, sum the values and after this check if they are the same. Something like: BigDecimal a = new BigDecimal(45.58); List lista = new ArrayList(); BigDecimal sum = new BigDecimal("0"); for(int…
0
votes
2 answers

Ruby BigDecimal - Having Conceptual Problems

I am trying to transfer money from one "account" to another: puts ("\nTransfer how much?") require 'bigdecimal' amount = gets.chomp amount = BigDecimal(amount) #<--Does BigDecimal have to work with strings??? puts ("\nTransfer to which…
labelcd6
  • 119
  • 1
  • 5
0
votes
2 answers

adding double variables inside a loop

i code a program in C#, this time i have to write in java and when i tried to add and subtract a simple number such like: double array1 = new double array1[200]; double array2 = new double array2[200]; for (int var = 1; var < 200; var++) { …
JUAN
  • 523
  • 4
  • 10
  • 27
0
votes
1 answer

scala play form how handle java bigdecimal

I try to fill a form with the values of System def edit(id: Long) = IsAuthenticated { username => implicit request => User.findByEmail(username).map { user => System.findById(id).map { system => Ok(html.systems.editForm(id,…
mbrambley
  • 245
  • 3
  • 10
0
votes
2 answers

BigDecimal assign operator

I have a problem with assigning one big decimal value to another I am trying such as creating one temp big decimal and add 0 to another big decimal BigDecimal temp = new BigDecimal(0); dropStartValue = temp.add(newCounterValue); However, I only…
soField
  • 2,536
  • 9
  • 36
  • 44
0
votes
2 answers

Any number type to BigDecimal

After a lot of messing around I came up with the following code to convert any Number subclass into a BigDecimal. I'm not convinced however that this code is fully correct. I'm certainly not happy about how verbose it is! Is there a better way…
GordonM
  • 31,179
  • 15
  • 87
  • 129
1 2 3
99
100