Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7525851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:40:02+00:00 2026-05-30T03:40:02+00:00

I just cannot find the correct answer, so here is my problem: I want

  • 0

I just cannot find the correct answer, so here is my problem: I want to be able to calculate the indexation (a positive or negative percentage) over a price and period.

Expectations:


Case #1
Price : 1.000,00
Indexation percentage : 5%

Calculation over 5 years with positive percentage:

1. 1000 x 5^0 = 1000
2. 1000 x 5^1 = 1050
3. 1000 x 5^2 = 1102,50
4. 1000 x 5^3 = 1157.625
5. 1000 x 5^4 = 1215,50625

Case #2
Price : 1.000,00
Indexation percentage : -5%

Calculation over 5 years with negative percentage:

1. 1000 x -5^0 = 1000
2. 1000 x -5^1 = 950
3. 1000 x -5^2 = 902,50
4. 1000 x -5^3 = 857,375
5. 1000 x -5^4 = 814,50625

Results:


And this negative percentage goes wrong, because my java code prints this out:

1000
-5000
-125000
15625000
1175690408

My code is pretty simple, i think:

BigDecimal percentageValue = new BigDecimal("-5");
BigDecimal indexation = percentageValue.divide(ONE_HUNDRED).add(BigDecimal.ONE);
BigDecimal price = new BigDecimal("1000");

for (int i = 0; i < 5; i++)
{
  price = price.multiply(indexation.pow(i));
  System.out.println(price.intValue());
}

Solution:

static final BigDecimal ONE_HUNDRED = new BigDecimal("100");
public static void main(String[] args)
{
 BigDecimal percentageValue = new BigDecimal("-5");
 BigDecimal indexation = percentageValue.divide(ONE_HUNDRED).add(BigDecimal.ONE);
 BigDecimal price = new BigDecimal("1000");

 for (int i = 0; i < 5; i++)
 {
   BigDecimal result = price.multiply(indexation.pow(i));
   System.out.println(result);
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:40:04+00:00Added an answer on May 30, 2026 at 3:40 am

    You should multiply by 1 + percents/100, 1% is 1/100.

    Note that 5% intrest over one years makes 1000 become 1050 and not 5000

    so for 5%: 1.05^n and for negative [-5%]: 0.95^n

    You can use BigDecimal to do it, since the numebrs are not integers.

    EDIT: [as respond to editted question] Your editted code does not produce the output you gave [assuming ONE_HUNDRED is initialized properly], however it still has a new issue:

      price = price.multiply(indexation.pow(i));
      System.out.println(price.intValue());
    

    look at the second iteration, you already set price = price * indexation^1

    When you multiply it again with indexation^i [i==2] you get a wrong result!

    A solution could be one of those:

    1. no need to pow() here, just multiply each iteration with the indexation.
    2. Do not override price, hold the result of price.multiply(indexation.pow(i) in a new temp variable – and print it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot find where the sqlcmd is? i just want the prompt. please help!
Just a simple question since I cannot find the correct url on the Jboss
Just would like to make clear, I cannot find straight answer. C# is general
I have just started using silverlight 2 beta and cannot find how to or
Maybe it's just doesn't exist, as I cannot find it. But using python's logging
I just want to understand why I cannot create a protected enum on C#?
This should be very simple, but I cannot find the correct syntax using search.
I just cannot imaginate a way to do a call to a function with
I just cannot get this to work, would appreciate if someone can help. So
I just cannot figure this out, it looks really simple but I'm relatively new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.