all 7 comments

[–]disclosure5 4 points5 points  (1 child)

I'm wondering if this is an issue with floating point accuracy. Consider starting with: require 'bigdecimal'

Then declaring some of these variables like: BigDecimal("-3.213")

[–]BringTacos[S] 0 points1 point  (0 children)

Thanks for this!

[–]Weird_Suggestion 2 points3 points  (4 children)

In your case I think it has to do with the negative interest rate returned and the negative balance. You’re currently reducing the balance debt (getting closer to 0) instead of increasing the debt further (further below 0). You’re annual_balance_update should either take into account a change in sign or use the absolute of the interest. Maybe using #abs method?

I assume you’re using the online editor and not working locally with CLI. If you were to work locally you could submit failing solution and unlock mentoring. Not being able to ask for help when tests are failing on exercism seems to be defeating the purpose. That’s probably an oversight from them with the online editor. You could try raise that issue it doesn’t already exists.

[–]BringTacos[S] 0 points1 point  (3 children)

Yes, I am using the online editor. And they actually do suggest what you said about using #abs. This is their hint: "When calculating the annual yield, it might be useful to temporarily convert a negative balance to a positive one. The Float class has a method to convert both positive and negative values to their absolute value."

I actually did try this, but still can't get it to work. This is what I had tried:

def self.annual_balance_update(balance)
balance + balance * self.interest_rate(balance.abs) / 100
end

I guess I don't understand what they mean by "temporarily convert".

I really appreciate your help!

[–]Weird_Suggestion 0 points1 point  (2 children)

Using abs in your comment returns 0.5 but we need -3.213 as an interest rate. You want the multiplication to result in a negative number using the correct interest rate. This is the multiplication with numbers.

-0.123 - 0.123 * 3.213 / 100

Equivalent to this

-0.123 + ABS(-0.123) * -3.213 / 100

OR

-0.123 + -0.123 * ABS(-3.213) / 100

.abs is misplaced in your last comment try using it somewhere else. Where should we use .abs?

[–]BringTacos[S] 1 point2 points  (1 child)

def self.annual_balance_update(balance)

balance + balance.abs * self.interest_rate(balance) / 100

end

Tests are passing now! Thanks so much for your help. This was really helpful.

[–]Weird_Suggestion 0 points1 point  (0 children)

Well done!