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
4 answers

When shall use float type in Java?

I know float type is A IEEE floating point, and it's not accuracy in calculation, for example, if I'd like to sum two floats 8.4 and 2.4, what I get is 10.7999999 rather than 10.8. I also know BigDecimal can solve this problem, but BigDecimal is…
Saorikido
  • 2,173
  • 2
  • 26
  • 37
0
votes
1 answer

Getting much higher precision with BigDecimal (or another class) in Java

I want to compute numbers with arbitrarily long decimal values (suppose I want to take a 100 decimal digits for a particular number). //Take the square root of 2 for 100 digits in total. public class Main { public static void main(String[] args)…
user4728253
0
votes
1 answer

How to convert time to bigdecimal with ruby?

For example, I have a time data with string format: 00:25:23;16 I want to convert it to BigDecimal and tried: a = '00:25:23;16'.to_d => # When I check a: a.floor => 0 It looks not the true value. Then how to…
s_zhang
  • 847
  • 2
  • 8
  • 16
0
votes
2 answers

Dynamic Reports BigDecimal

I am trying to build a report with multiple columns. I have a column total that represents the summation of the previous columns. However, the value I am getting is of type BigDecimal and the return type of the .add method is BigDecimal and not…
Abdalla Ismail
  • 409
  • 1
  • 4
  • 21
0
votes
1 answer

Scaling issue in BigDecimal(java) for exponential notation

In our application, we need to check whether the given number is in range or not and for this we are using below code - boolean isValidRangeNumber(Double no,int precision, int scale){ BigDecimal bigDecimal = new…
Sanchi Girotra
  • 1,232
  • 13
  • 13
0
votes
0 answers

Rewrite float into BigDecimal

I want to calculate values from Java List. I managed to create the code using float in order to store money amount. private float sumAmounts(List myList) { float total = 0.0f; for (ExpressCheckout item :…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
0
votes
1 answer

Saving JSON hash value as decimal - Ruby on Rails

I'm trying to save an amount that is sent via JSON to my postgreSQL database in a decimal column. The hash looks something like this: {"status"=>"success", "data"=>{"network"=>"BTCTEST", "address"=>"2MstFNxtnp3pLLuXUK4Gra5dMcaz132d4dt",…
0
votes
1 answer

Is there awesome_print like gem for Minitest result

I'm using awesome_print, because I want to see Bigdecimal numbers like 0.5, instead of . And I also want to use same function for Minitest result. Is there a gem for it? I tried minitest-reporters, but…
ironsand
  • 14,329
  • 17
  • 83
  • 176
0
votes
1 answer

Rounding at specific precision with ApFloat

ApFloat http://www.apfloat.org/ is a C/C++/Java math library that can calculate many trascendental operations such as square roots, exponentiations, logarithms, trigonometric/hyperbolic functions, numeric value of π, etc. with numbers of arbitrary…
0
votes
0 answers

Method to parse whole String into BigDecimal

I am looking for method/way to accomplish this: try { DecimalFormat decimalFormatter = new DecimalFormat(); decimalFormatter.setParseBigDecimal(true); decimalFormatter.parse(inflowTextField.getText()); } catch(ParseException…
ssukienn
  • 558
  • 6
  • 22
0
votes
1 answer

NumberFormatException when parsing a String to BigDecimal

My Code is : String sql="insert into L_EC(AMOUNT)values(?)"; pst=con.prepareStatement(sql); for(int i=0;i
Squero27
  • 21
  • 1
  • 7
0
votes
2 answers

Round BigDecimal Depending on tenth place value

Let's say I have a BigDecimal that can be any number of values. If the tenth place value is less than 3 (i.e. 12.2, I want to round down to 12). If the tenth place value is greater than or equal to 3 (i.e 11.3), I want to round the tenth value up to…
user3029486
  • 289
  • 1
  • 3
  • 10
0
votes
3 answers

Is there a way to make BigDecimal faster than I have here?

I'm working on some financial analysis software that will need to process large (ish) volumes of data. I'd like to use BigDecimal for the accuracy (some pricing info goes to four or five digits to the right of the decimal) but I was concerned about…
vocalionecho
  • 301
  • 4
  • 9
0
votes
1 answer

What does big decimal precision zero mean in java

I treated 500 as BigDecimal in java. And i turned into {・UnscaledValue = 5 ・Scale = -2 ・Precision = 0} I really don't understand why precision is 0. I thought it might be 1. Can anyone explain?
Aki
  • 9
  • 2
0
votes
1 answer

I need to handle NumberFormationException or NaN to BigDecimal

I am getting below error, com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Infinite or NaN When I am giving Json request: {"sendAmt" : ""} and storing that json object to some other Object using…