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

Monetary fields html with sql server and J2EE

I realized an invoicing application in J2EE(jsp,servlet), after having finished my program and tests, I noticed the following error: my sql server table FACTURE contains: Price NUMERIC (6,2) the user enters 333.33 is good but WHENE HE enters 333333…
najeh22
  • 231
  • 1
  • 2
  • 11
0
votes
1 answer

How to divide a bigdecimal object coming from OCI8 recordset?

def main() myDB=DB.new('myUser','myPass','myDB') record = myDB.handle().select_one('select count(*) from things') printf "%10d" % record end main() result: 30008428 I want to divide this value by 24 to create batches which will be executed…
Nicolas de Fontenay
  • 2,170
  • 5
  • 26
  • 51
0
votes
1 answer

How can I fix this poor BigDecimal rounding?

I'm having some trouble rounding BigDecimals in java. I'm trying to convert a value from feet to inches and vice versa, this is what I have: //To convert from ft to in; //... BigDecimal CINCH = new…
Luso
  • 125
  • 2
  • 9
0
votes
1 answer

Larger data decimals than BigDecimal

I recently made a basic Pi calculator that works with Math.BigDecimal. It outputs to a text file, and calculates extremely fast, but even BigDecimal has it's limits. I was wondering what the basic code would be for numbers even more precise (Not…
0
votes
1 answer

BigDecimal or SQL aggregate functions?

I have an Android app that I'm handling money in. I heard that BigDecimal was the best for handling money and I was having trouble dealing with string representation of different currencies, so I switched from float to BigDecimal. However, I've…
0
votes
1 answer

Cut a long decimal fragment to exact tow decimal

I made an application in android withthe help of decimal format #.##. but i need to get exact first tow decimals of the fractional number.i dont want to get round the number. is there any coding for that plese tell me
0
votes
8 answers

Why is BigDecimal more precise than double?

I would like to know the exact difference between BigDecimal and double. I know that BigDecimal is more precise than double and you should use the former for calculations. Why is it more precise? Why isn't it possible to customize double so that it…
Obl Tobl
  • 5,604
  • 8
  • 41
  • 65
0
votes
1 answer

Why is bundle installing the wrong version for bigdecimal using 1.2.0?

I'm using Bundle to install gems in d:/cucumbertests/cucumber/ successfully, which installs BigDecimal v 1.1.0. This failed in d:/cucumbertests/cucumber/itinfix which installed BigDecimal v 1.2.0. How do I identify the correct version of BigDecimal…
Eric Xu
  • 1
  • 1
0
votes
1 answer

Ruby 1.8.6 BigDecimal.to_f always returns '0,0' on Solaris

I have come across a very weird error. I'm on Solaris 10, using Ruby Enterprise Edition (ruby 1.8.6 (2008-08-08 patchlevel 286) [i386-solaris2.10]) with Rails 2.3.4. I have a very weird error. In irb: irb(main):001:0> require 'bigdecimal' =>…
0
votes
1 answer

Compare if BigDecimal is equal to zero in jsp

I am comparing a big decimal value in jsp like this, but some how it doesnt seem to work. Any idea on what am i missing…
ACP
  • 34,682
  • 100
  • 231
  • 371
0
votes
1 answer

android big decimal approximation

I want to approximate a number showing only two digits after the decimal point. I wrote this: String result = String.valueOf(new BigDecimal(price).setScale(4, BigDecimal.ROUND_UP).doubleValue()); If price is a decimal number like 63,9222, it works…
MikeKeepsOnShine
  • 1,730
  • 4
  • 23
  • 35
0
votes
5 answers

BigDecimal Exception message

What does this means? Exception in thread "main" java.lang.NumberFormatException java.math.BigDecimal.(Unknown Source) But when I click on the line that would be causing the problem, there was no warning nor error. So, how do I resolve this…
Melvin Lai
  • 861
  • 3
  • 17
  • 35
0
votes
1 answer

DecimalFormat is being overridden by server settings

Currently I'm having a problem displaying formatted decimals. In my local machine I have a decimal value: 0.002100000000 stored in database.
czetsuya
  • 4,773
  • 13
  • 53
  • 99
0
votes
1 answer

Rounding a BigDecimal in Java doesn't return the expected number

I have a property called m_FOBST which contains the following number: 1.5776. Here I'm trying to round it: this.m_FOBST.setScale(2, BigDecimal.ROUND_HALF_EVEN) However, I get the number 1.60 when I should be getting 1.58. Can anyone explain why?
0
votes
1 answer

dividing bigdecimal containing bigger dividers than scale

I want to find a way to scale divisions of bigdecimals that can contain diverse numbers. if I use this code: r= x.divide(y,10, RoundingMode.HALF_UP); the result of almost all results are correct, but if I have a divisor with more digits before…
Dors
  • 5
  • 1
  • 3
1 2 3
99
100