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

Handling very small numbers in Ruby

I want to multiply more than 10K probability estimates (values between 0 and 1). I am using Ruby. And I used BigDecimal to store the small numbers like, prod = BigDecimal.new("1") prod = prod * BigDecimal.new("#{ngramlm[key]}") but after few…
drsbhattac
  • 109
  • 2
  • 7
0
votes
0 answers

Java: Why won't this BigDecimal loop work?

I'm trying to calculate pi using the Gregory-Leibniz method to a user-specified number of decimal places. I've never worked with the BigDecimal class before, so I don't know what I am missing here. A simple explanation of the Leibniz method can be…
Bassinator
  • 1,682
  • 3
  • 23
  • 50
0
votes
1 answer

Is there any condition where Bigdecimal with MathContext.DECIMAL32 does not provides correct result?

System.out.println("Result="+new BigDecimal(((63.19* 15) + (63.37* 5))).divide(new BigDecimal(15 + 5), MathContext.DECIMAL64).doubleValue()); Result=63.23499999999999 But with MathContext.DECIMAL32 we are getting correct result, see…
A_Coder
  • 3
  • 3
0
votes
1 answer

Ruby on Rails Why do I get the error: Array can't be coerced into Fixnum

I am making a cinema system in Ruby on Rails, I am currently trying to get it to display the total price of each booking. I am trying to do this through this method in booking.rb: def total_price adult_price = Price.where("name = ?",…
user4227507
0
votes
1 answer

Getting NaN / Infinity Error when converting Double to BigDecimal

So I have this division between doubles (from values it gets in a database); indPayRatio[loadCounter] = c.getDouble(c.getColumnIndex("payment")) / c.getDouble(c.getColumnIndex("debt_total")); There is no case where either of the values can be…
TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259
0
votes
3 answers

Adding the elements of a BigDecimal Array in java

I am new to Java and I came up to this error in my program where I can't add the elements in an array of BigDecimal elements. I successfully made it with Integer and Double types but when I change the type to BigDecimal, it won't work at all.…
0
votes
1 answer

Java BigDecimal - rounding down to the user-provided multiple

I have a business requirement where the input values should be rounded down to the multiples provided by user. Here is the example: Case | input | multiples | output 1 | 43.0 | 0.1 | 43.0 2 | 43.1 | 0.1 | 43.1 3 | 43.2 | 0.1 …
MFIhsan
  • 1,037
  • 3
  • 15
  • 35
0
votes
0 answers

java.lang.NullPointerException BigDecimal

I'm working in a java project. This is Article (Artikujt) class emri = name, cmimi = price; import java.math.BigDecimal; import java.sql.*; public class Artikujt { Connection conn; String emri; BigDecimal cmimi; int kat_id; public…
em7wo
  • 1
0
votes
1 answer

Java-Returning BigDecimal as String: Returns int

I'm using a fraction to add to the current BigDecimal. It keeps returning an int. Not sure what I'm doing wrong. //within a class function public BigDecimal result = new BigDecimal(1); int x = 2; double g = 1/x; result = result.add(new…
JCoder
  • 189
  • 1
  • 3
  • 17
0
votes
1 answer

To understand BigDecimal class Arithmetic and Object Behaviour

public final class Test{ public static void main(String args[]) throws Exception { BigDecimal bigDecimal_One = BigDecimal.ONE; System.out.println(bigDecimal_One); bigDecimal_One.add(BigDecimal.ONE);// 1. As I have not…
Shirishkumar Bari
  • 2,692
  • 1
  • 28
  • 36
0
votes
1 answer

What is the equivalent of the Java BigDecimal class in IOS

I have a request model class in server with BigDecimal Properties. While using the same in IOS Client application,What data type i should use? I tried with double,float,NSnumber,NSDecimalNumber but nothing works. Exception is raised in server while…
Sudeep george
  • 111
  • 1
  • 11
0
votes
1 answer

Scala BigDecimal fails to translate a decimal String representation created by itself

While playing around with generative testing I came across the following: import org.scalacheck.Properties import org.scalacheck.Prop.forAll object BigDecimalSpec extends Properties("BigDecimal") { property("apply") =…
Kaarel Nummert
  • 989
  • 8
  • 20
0
votes
1 answer

GWT, BigDecimal and RPC always returns 0

I'm having a lot of troubles with creating a BigDecimal object on the client side and send it to the server via RPC. When I read the toString or toPlainString method of BigDecimal on the server side, it always returns 0. On the client side, the…
Rasmus Nielsen
  • 411
  • 1
  • 4
  • 18
0
votes
2 answers

Conversion of BigInteger to BigDecimal without new Operator

How can I convert BigInteger value to BigDecimal without using new operator? For instance, if I have an integer value like: abc=4000. I should get the output as: xyz= 4000.0
Vishnu
  • 176
  • 1
  • 2
  • 19
0
votes
1 answer

Issues facing while rounding off big decimal value

We have one page where we are fetching the data from database. one field "AmountEur" is there which is getting rounding off (using bigdecimal.ROUND_HALF_UP method) before showing it up on view page. the code is like this : final Object amountEur =…
user2326831
  • 151
  • 2
  • 14