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

Using BigDecimal in number factorisation

I would like to archive number factorisation in java but am getting errors when try to run the program.I am also getting unrealiable results but am convinced this should work. Below is my code import java.math.*; public class FactorizerBig{ …
Emma
  • 323
  • 3
  • 16
0
votes
0 answers

What's the best way to fail String to BigDecimal conversion hard?

Here's what I have now: String text = "-9,23"; Character character = '.'; DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(character); symbols.setGroupingSeparator(character.equals('.') ? ',' :…
goe
  • 1,153
  • 2
  • 12
  • 24
0
votes
1 answer

BigDecimal adding in java

I am trying to add together several large numbers to make a weighted fraction. If there are three numbers going into the fraction(a, b, c), the weighted fraction should be : (1/a)/((1/a)+(1/b)+(1/c)) For now I am only trying to correct the…
user3369920
  • 83
  • 1
  • 1
  • 11
0
votes
1 answer

How to remove a $ sign from a string before updating DB

I need help on how to remove a $ signs from a string before updating DB Currently in my application the from end on default adds a $ as a first character. I need to know how I can remove that because I get the Big Decimal error when updating…
user2149910
  • 87
  • 3
  • 12
0
votes
1 answer

Receiving "Not a valid char constructor input" error when passing decimals

I am receiving "Not a valid char constructor input" when passing decimal. My code is below. I have researched and found that by changing from BigDecimal to Formatdeciaml solves the problem, but I can't do that because then my mapper needs to be…
user2149910
  • 87
  • 3
  • 12
0
votes
1 answer

Android BigDecimal how using write?

I used BigDecimal for rounding money value. And I have question. float price = 0.71F; BigDecimal priceA = BigDecimal.valueOf(price).setScale(2, RoundingMode.FLOOR); //priceA == 0.70; float price = 8.71F; BigDecimal priceB =…
smail2133
  • 936
  • 2
  • 7
  • 24
0
votes
2 answers

Can you replicate the Floor function found in Excel in Java?

I have searched the internet but have not found any solutions for my question. I would like to be able to use the same/replicate the type of FLOOR function found in Excel in Java. In particular I would like to be able to provide a value (double or…
Michael
  • 87
  • 1
  • 2
  • 11
0
votes
1 answer

Double data type not returning desired output in java

In Java, for the following code Double d = 2.0-1.1; System.out.println(d); The result is 0.8999999999999999 If the program is dealing with sensitive information such as precentile/money or cents how do I solve this problem? I also tried the…
Arun
  • 1,176
  • 5
  • 20
  • 48
0
votes
2 answers

BigDecimal to String in java?

My code is: x=new BigDecimal(x.toString()+" "+(new BigDecimal(10).pow(1200)).toString()); I am trying to concat two bigdecimals after converting them to string and then convert them back to bigdecimal.I am doing so because x has a value with a…
user1613360
  • 1,280
  • 3
  • 16
  • 42
0
votes
2 answers

Writing custom code to compute BigDecimal powers

I'm working on a calculator in order to better learn Java. I've written my own code to calculate powers with BigDecimal parameters. As of now, the code cannot handle fractional powers, such as 2^2.2. In order to tackle this problem, I want to…
pez
  • 3,859
  • 12
  • 40
  • 72
0
votes
1 answer

Jeresy Jackson BigDecimal Post

I've come up against a problem. i can't properly use BigDecimal in my own class, to do post actions. hope for advice Using Jersey 2.x, Jackson 1.8 my class public final class TestModel{ private BigDecimal ffff; public BigDecimal getFfff()…
0
votes
1 answer

BigDecimal Substract with negative result

I have this code: public BigDecimal getDifference() { BigDecimal total = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_DOWN); for (Order order : orders) { BigDecimal originalCost= order.getOriginalValue(); BigDecimal…
mario595
  • 3,671
  • 7
  • 34
  • 57
0
votes
1 answer

How to use ApfloatMath.round()?

In this snippet I expected "2" as the result? Apfloat f = new Apfloat("1.5", 50); f = ApfloatMath.round(f, 15, RoundingMode.HALF_UP); System.out.println(f.toString()); Or should ApfloatMath.round() be used differently?
axelclk
  • 950
  • 9
  • 28
0
votes
1 answer

BigDecimal is not rounding good with ROUND_HALF_UP

I am creating an app to calculate a mark average with percents, but the problem is that BigDecimal not always rounding the average, for example if the mark average is 3.85 BigDecimal ROUND_HALF_UP in scale 1 should round to 3.9 but it show the…
0
votes
4 answers

How to format BigDecimal with 2 fractions?

I'd like to format and display BigDecimal numbers with always to fractions. No other separators should ever be displayed. How could I achieve it? The following does not work. NumberFormat formatter =…
membersound
  • 81,582
  • 193
  • 585
  • 1,120