This question already has answers here:
How to do a fractional power on BigDecimal in Java?
(3 answers)
Java's BigDecimal.power(BigDecimal exponent): Is there a Java library that does it? [closed]
(3 answers)
Closed 8 years ago.
BigDecimal was the choice to store numbers that have up to 5 digits after decimal point. I need to raise the BigDecimal to fractional power (up to 2 digits after decimal point).
For example I have to bring 9.09671 to power of 1.51. Do I need some conversions from/to BigDecimal? How to do it?
EDIT:
I cannot use 3rd party libraries as described in Java's BigDecimal.power(BigDecimal exponent): Is there a Java library that does it?
Is there more elegant, succint way for this case than described in How to do a fractional power on BigDecimal in Java?
Related
This question already has answers here:
BigDecimal setScale and round
(2 answers)
Set specific precision of a BigDecimal
(5 answers)
Closed 1 year ago.
I am trying to write a program that has a step in it where I would like to divide two numbers and get a decimal number to 60 places.
For instance, I would like to divide 1 by 17 and get 0.016393442622950819672131147540983606557377049180327868852459 without losing any precision.
I am trying to store the number in a BigDecimal but I am having trouble finding a good way to accomplish this without losing the precision after the 16th digit or so
This question already has answers here:
Large Numbers Requiring More than 64 bit Representation
(5 answers)
Closed 2 years ago.
In a project that is related to security,
it is required to deal with very huge prime numbers such as:
3136666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666313
I am using java, and as it is know that maximum number that could be declared is 64-bits (type long)
So is there any approach to deal with these numbers?
You can use BigDecimal from java.math package:
BigDecimal longerThanLong = new BigDecimal("9223372036854775808");
This question already has answers here:
Java BigDecimal remove decimal and trailing numbers
(6 answers)
Closed 6 years ago.
I have a BigDecimal number, I just want to remove the decimal numbers from it,
for example if I have 200.88 then output should be 200?
I tried Bigdecimal rounding function but they wont do the job
You can specify the rounding mode to ROUND_FLOOR when you use round.
This question already has answers here:
How many significant digits do floats and doubles have in java?
(6 answers)
Closed 7 years ago.
I have a problem when it comes to calculating pi with more than 15 decimal places(i used double).
My result looks quite good except my variable is limited to 15 decimal places:
3.140592653839794
Anybody could tell me what i have to do if i want more decimal places?
Thanks and Greeting!
Use java.math.BigDecimal instead of double for arbitrary (finite) precision.
This question already has answers here:
How can I handle precision error with float in Java?
(9 answers)
Closed 8 years ago.
some calculations with doubles return the wrong result.
E.g.
System.out.println(""+(0.05+0.01));
output
0.060000000000000005
What can I do to correct this error?
Doubles are not made for precise calculations (see Round to 2 decimal places) - for precise calculations, use BigDecimal instead.