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

Regarding BigDecimal

I have a csv file where amount and quantity fields are present in each detail record except header and trailer record. Trailer record has a total charge values which is the total sum of quantity multiplied by amount field in detail records . I…
Arav
  • 4,957
  • 23
  • 77
  • 123
0
votes
1 answer

How to bind BigDecimal value to Currency in Spring

Hi I am using jquery autoNumeric to format my input values in currency format. I want to bind these formatted values to BigDecimal in SpringPortlet. Please let me know how I can do it ?
0
votes
1 answer

My while statement isnt working with my BigDecimal

public static void main(String[] args) { //Creates the BigDecimal and scanner used BigDecimal answer = new BigDecimal("0"); Scanner scan = new Scanner(System.in); //While statement to repeat if they dont answer 1 or 2 while…
0
votes
2 answers

BigDecimal multiplication returns 0?

I'm a bit of a newbie at Java and I have to multiply 52 numbers with each other ranging anywhere from 0 to 2000. I already tried using *= without BigDecimal but the result gives me 0.0. Here is my code: BigDecimal productOfStock1 =…
0
votes
1 answer

Check decimal precision of Floating points

I want to validate that a float or Double has minimum 5 numbers after decimal points.This is the code I have written private boolean invalidDecimalPrecision(Double point) { int decimalPrecision = BigDecimal.valueOf(point).scale(); return…
Abhijeet Kushe
  • 2,477
  • 3
  • 26
  • 39
0
votes
1 answer

Java cannot import org.nevec.rjm package

I need to be able to perform calculations on numbers that extend to very many decimal places. I am using the BigDecimal class, but I need to be able to take logarithms of these BigDecimals and I also need Euler's number to many decimal places. I am…
Severus
  • 3
  • 1
0
votes
2 answers

Why does it keep rounding when I use BigDecimal

So I am trying to calculate my average goals blocked by dividing how many I stopped by how many shots have been taken. How can I stop it from rounding my average counter = goals blocked goalCounter = goals scored avg.setOnClickListener(new…
0
votes
1 answer

Spring Batch : PassThroughFieldExtractor with BigDecimal formatting

I'm using Spring Batch to extract a CSV file from a DB table which has a mix of column types. The sample table SQL schema is [product] [varchar](16) NOT NULL, [version] [varchar](16) NOT NULL, [life_1_dob] [date] NOT NULL, [first_itm_ratio]…
emeraldjava
  • 10,894
  • 26
  • 97
  • 170
0
votes
3 answers

Obtaining the sum of an array list that contains complex decimals

I'm brand new to to Java and looking with some help. I have an array list as follows: double number[]={19.1904990290,27.2646233344,51.4850317134} I've used the following code to sum the array list and print it to the console: int sumLeft = 0; …
0
votes
1 answer

Format BigDecimal to string with scientific notation and viceversa

I have a function called factorial which calculates factorial for a large number and returns in BidDecimal BigDecimal temp_val1 = factorial(555); the above gives 66140856092779467090983316712427699021235xxxxxxxxxxxxxxxxxxxxx Now i have to format…
Giri Dhar
  • 149
  • 2
  • 12
0
votes
1 answer

Convert to correct BigDecimal representation

I have a string being returned as a data feed which I need to convert to the correct BigDecimal format - the string is of the format 1.6945E3 and needs to translate to 1694.50 but instead translates only to 1694.5 leading to loss of information.…
user3095976
  • 135
  • 1
  • 1
  • 11
0
votes
1 answer

NumberFormatException probably the BigDecimalInvalid long: "1,00" android-sdk-paypal

I have this error when I try to convert a double to bigdecimal BigDecimal bb = new BigDecimal(""+total); Log.i("","voila le bigdecimal : "+bb); PayPalPayment thingToBuy = new…
begiPass
  • 2,124
  • 6
  • 36
  • 57
0
votes
1 answer

How can the scale of a BigDecimal be validated?

We currently have some code for validating a string as a BigDecimal of the correct scale that looks like: try { new BigDecimal(amount).setScale(4); } catch (Exception e) { //...something } I would prefer it looked a little more like…
j.davies
  • 2,321
  • 1
  • 19
  • 24
0
votes
4 answers

How to compute the double values in java with proper output?

I am writing mathematical function using Java and when I try to compare my result with ms office excel formula function the accuracy of the both the values missing which make my comparison(==) fails in case of double values. My…
user492888
  • 207
  • 3
  • 17
0
votes
1 answer

Compare BigDecimals as acceptably close based on their significant digits

I have two BigDecimals and I'd like to determine if they are close based on their significant digits. For example, consider the following: BigDecimal million = new BigDecimal(1_000_000); BigDecimal tenmillion = new…
dimo414
  • 47,227
  • 18
  • 148
  • 244