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

Can't assign bigdecimal to a field in model

[1] BigDecimal BigDecimal < Numeric [2] account.outstanding_balance = BigDecimal.new(0.3, 2) 0.3 [3] account.outstanding_balance 0 I cannot figure out why I am unable to assign account.outstanding_balance a decimal value of .3. This is a rails app…
Eric Francis
  • 23,039
  • 31
  • 88
  • 122
0
votes
1 answer

Rounding error in java

I have a Java function that's supposed to calculate dividend interest and Java keeps getting the output off by several digits. I'm having issue finding where the rounding error keeps coming up, so I made a crude copy of my function that breaks the…
Phreakradio
  • 176
  • 1
  • 18
0
votes
1 answer

ActiveRecord column decimal default value

I have a tableless class defined like this: class MyClass class MyClassRules < ActiveRecord::Base column :a, :integer column :b, :boolean column :c, :datetime column :d, :decimal, :precision => 10, :scale => 4 column :e,…
kid_drew
  • 3,857
  • 6
  • 28
  • 38
0
votes
2 answers

Set BigDecimal RoundingMode according to user option without if statements?

I have ~400 statements using RoundingMode.HALF_UP, and by the nature of the app, I'd like for the user to be able to choose between the rounding modes. However, I'm at a loss as to how to represent that as a variable, if possible. Because of the…
IHazABone
  • 525
  • 2
  • 6
  • 20
0
votes
2 answers

How Objective-C support Java BigDecimal via Hessian?

Server has a Java Bean, it has a instance variable type BigDecimal, but Objective-C cannot map it! I have tried NSNumber, but doesn't work. Does anybody know how to fix it?
Smeegol
  • 2,014
  • 4
  • 29
  • 44
0
votes
1 answer

BigDecimal precision above 1E22

for some reason I found myself coding some piece of software, that should be able to perfom some astronomic calculations. While most of it will be about transfering the correct formula into Java, I found an annoying Problem right at the verry…
Confused Merlin
  • 127
  • 1
  • 8
0
votes
2 answers

Is there API methods to convert BigDecimal(seconds) to years, months, days, hours, minutes, seconds?

The title of the question includes all the details. If I have BigDecimal seconds = new BigDecimal("32365423.56"); Is there API methods that convert this to: n years, n months, n days, n hours, n minutes, n seconds. If time is ambiguous in seconds,…
Saleh Feek
  • 2,048
  • 8
  • 34
  • 56
0
votes
1 answer

BigDecimal Calculation Error at Jython

I try to run BigDecimal LOADPROCESSID = BigDecimal(461).Add(new BigDecimal(1)) at Jython. However, I got error message BigDecimal LOADPROCESSID = BigDecimal(461).Add(new BigDecimal(1)) ^ SyntaxError: mismatched input 'LOADPROCESSID'…
0
votes
2 answers

Precision decimals, 30 of them, in JavaScript (Node.js)

My Challenge I am presently working my way through reddit's /r/dailyprogrammer challenges using Node.js and have caught a snag. Being that I'm finishing out day 3 with this single exercise, I've decided to look for help. I refuse to just move on…
bitfed
  • 347
  • 4
  • 11
0
votes
1 answer

JTextField Specific format checking

I want to check if the input entered to my JTextField1 equal to shown sample picture below, how to do that? I can only check if numbers entered by putting below code in to try block and catch NumberFormatException try { taxratio = new…
user3498019
  • 95
  • 1
  • 2
  • 10
0
votes
2 answers

Java BigDecimal Rounding

I am learning BigDecimal and i want it to retrieve the exact number i entered, the following code is rouding the number and i dont know why public static BigDecimal parseFromNumberString(String numberString) { if (numberString != null) { …
Mauro M
  • 669
  • 1
  • 8
  • 25
0
votes
1 answer

BigDecimal formatting

I'd like to format a BigDecimal in Java to 8 Characters (including the seperator), rounding HALF-UP. Some examples: 12345.6789 -> "12345.68" 123 -> " 123.0" 0.12345678 -> "0.123457" 1.5 -> " 1.5" 0.0045 -> " 0.0045" 12 …
0
votes
1 answer

Operation from float to BigDecimal in Java

I'm doing a math operation beetwen hours, but I've a problem with the float (the java virtual machine approximate is not perfect). So, I decided to convert this operation in BigDecimal...but I've some problems with results.. This is the original…
user3449772
  • 749
  • 1
  • 14
  • 27
0
votes
2 answers

Properly scaling BigDecimal

I have a situation where I want to scale values but in certain situations I'm getting an exception that indicates that rounding is required. Lets say I have the numbers -9.999999 and 9.999999 Lets also say that I only care about precision up to 4…
Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
0
votes
2 answers

WSDL2Java Eclipse plugin BigDecimal Issue

I'm attempting to generate Java code from a WSDL file. It generates the code but there seems to be an issue with one of the auto generated setter methods. /** * Auto generated setter method * @param param Curr132 */ public void…
sb89
  • 353
  • 1
  • 6
  • 23