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

BigDecimal division

I'm trying to use BigDecimal to calculate the GST tax rate. The tax calculation is supposed to be 1/11 * item price. So I thought I should probably use the BigDecimal to give the most accurate representation. But for some reason the rate is always…
Richard G
  • 5,243
  • 11
  • 53
  • 95
0
votes
1 answer

BigDecimal division issue

I have two fields in my struts form as: Long currentUsage; // 209715200l BigDecimal totalQuota; // 343597383680 On jsp I'm using el to display the percentage as:
Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
0
votes
4 answers

How to get Integer of BigDecimal without separator

I got the following BigDecimal from a Money-Object: BigDecimal 49.99 and I need this as Integer 4999, so everything I ask for is getting rid of the separator. I could get this BigDecimal as String and remove the separator and parse it to an Integer,…
PreDer
  • 113
  • 3
  • 11
0
votes
1 answer

How to use BigDecimal to achieve following code instead of using double or float?

I have this code public static double distance(double lat1, double lon1, double lat2, double lon2, char unit) { double theta = lon1 - lon2; double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1))…
Kishore Kumar Korada
  • 1,204
  • 6
  • 22
  • 47
0
votes
1 answer

Scala: large calculation losing value to zero/infinity

I'm trying calculate a perplexity value for a language model and the calculation uses a lot of large powers. I have tried converting my calculation to log space using BigDecimal, but I'm not having any luck. var sum=0.0 for(ngram<-testNGrams) { …
user3297367
  • 79
  • 1
  • 1
  • 9
0
votes
1 answer

Two Dimensional Arrays with BigDecimal in Java

I am getting compiler errors that seem to point at the semicolon at the end of two statements, and I have no idea how to fix the problem. The goal is to take in values from an Enum Class in Java and use them in financial calculations with a two…
0
votes
1 answer

RoR decimal field with :precision => 10, :scale => 6 is not storing decimals

I have a decimal field that does not stores decimals, although the schema file says: t.decimal "kg", :precision => 10, :scale => 6 If I do: (15,000 * 1,010)/1,000,000 which should be 15.15 it will only show 15.00 On DDBB:…
Lut
  • 1,363
  • 1
  • 14
  • 30
0
votes
1 answer

Using BigDecimal to Print Pi: Code is inefficient and doesn't work

I've been playing around with BigDecimal today, and ended up with the code below. According to my compiler there are no problems, yet after running I get a few exceptions. Any help is appreciated, thank you very much :-) import…
BlurryZombie
  • 167
  • 1
  • 1
  • 8
0
votes
2 answers

How to parse BigDecimal into Text with EU decimal separator but no decimal numbers at the end?

I need to be able to be able to parse a "1.000," string into a BigDecimal with value 1000 and then parse that same BigDecimal back into a "1.000," string. Both should happen using the same exact DecimalFormat formatter. Why? Because I need to…
goe
  • 1,153
  • 2
  • 12
  • 24
0
votes
1 answer

Talend - NullPointer in BigDecimal.add()

I'm having an error on my Job when I do adding of BigDecimal on my tMap. this is my code. Var.var1.add(Var.var2).add(Var.var3).add(Var.var4) all of my variables are BigDecimal. my error is 'NullPointerException'. I already checked data on my…
dane rias
  • 21
  • 1
  • 11
0
votes
2 answers

what is the difference between the java.lang.Math class and the java.Math class

I am trying to figure out which 'Library' the BigDecimal Class resides in. When I read the referencing information it says this: java.lang.Object java.lang.Number java.math.BigDecimal which I don't totally understand. I am…
RoryG
  • 1,113
  • 1
  • 10
  • 20
0
votes
1 answer

String value from a JTable to BigDecimal throws Java.lang.NumberFormatException

I am making a graphing calculator that allows the calculation of data with errors (i.e. 5 +-0.02). I have created an object named Numbers3 which in its attributes has a BigDecimal variable. When I input the data trough the console, everything works…
0
votes
1 answer

Estimate BigDecimal Calculation time

I have made a scientific calculator which uses BigDecimal. It has a particularly resource-hungry feature, factorial. Now, typing ANY number fires up the calculation.Depending on the device that this code is being run on , the answer is displayed at…
harveyslash
  • 5,906
  • 12
  • 58
  • 111
0
votes
1 answer

Dealing with BigDecimals in JSF

I have one of the following BigDecimal converters. @ManagedBean @ApplicationScoped public final class BigDecimalGeneralConverter implements Converter { private static final int scale = IntegerConstants.MAX_FRACTIONAL_DIGITS.getValue(); …
Tiny
  • 27,221
  • 105
  • 339
  • 599
0
votes
1 answer

Bigdecimal logarithm in Java

I want to calculate the logarithm of the transmitter.getETXPOW(), what is BigDecimal format. BigDecimal power = transmitter.getETXPOW(); BigDecimal eirp = 10 * Math.log(power); I received an error message, BigDecimal can not be converted to…
user2342549
  • 45
  • 1
  • 2
  • 9