This content has been marked as final.
Show 4 replies

1. Re: BigDecimal and POW
TPDOpitz Apr 7, 2013 6:43 AM (in response to Zabo)please addtags around your samples when posting here... The wrong result is cause by your double values. native decimal numbers are not precise because of two resons: <ol><li>there is s limmited number of bits/bytes to represent the value. <li>binary representation used by the Computer differs from human readable decimal format in that way that some decimal fractions form entless binary fractions, wich connot be represented due to leck of bits/bytes </ol> Use only <tt>BigDecimal</tt> objects and their methods for calulation. bye TPD

2. Re: BigDecimal and POW
Zabo Apr 7, 2013 7:13 AM (in response to TPDOpitz)OK, according to what I red, I understood that BigDecimal is the solution.
But, How to compute power( BigDecimal, 1/365) ?
In the API, I saw only power(BigDecimal,int). 
3. Re: BigDecimal and POW
TPDOpitz Apr 7, 2013 8:28 AM (in response to Zabo)Zabo wrote:
http://en.wikipedia.org/wiki/Exponentiation#Arbitrary_integer_exponents
OK, according to what I red, I understood that BigDecimal is the solution.
But, How to compute power( BigDecimal, 1/365) ?
In the API, I saw only power(BigDecimal,int).
And since you're a lucky guy there's a lib for you:
http://krum.rz.unimannheim.de/jas/
bye
TPD 
4. Re: BigDecimal and POW
rp0428 Apr 7, 2013 4:49 PM (in response to Zabo)>
In the following example, I compute new_amount_d in 2 different ways and I get 2 different values although it should be the same in theory.
>
No  those would NEVER be the same in theory or in practice since they use two vastly different formulas.
The second line of code uses an exponent of '1' which means it doesn't compute a 'power' at all. Anything raised to the power of '1' is just the same value. The first example uses '1/365' as the exponent and that is way different than the '1' used in the second example.new_amount_d = new_amount_d * Math.pow(1+interest_rate_d,(double)1/365); . . . new_amount_d = amount_d * Math.pow(1+interest_rate_d,(double) 1);
>
I'm new to Java and I'm working for financial industry...that's why I'm trying to solve this problem.
>
Then start over and tell what the actual problem is that you are trying to solve.
What are you trying to compute? What financial formula are you trying to use?
Forget your code and provide an example, in English, showing:
1. the input values
2. what you are trying to compute
3. the expected output values.
Then someone can try to help you find the best way to do that.