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 883989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:41:01+00:00 2026-05-15T12:41:01+00:00

What is a simple piece of code to read a stored number, calculate interest

  • 0

What is a simple piece of code to read a stored number, calculate interest on the stored value, say $100, at a rate of %10. Then I store the new value in place of the old one. I was working towards this:

NSNumber *bankTemp = [[NSNumber alloc] initWithInt:[[NSUserDefaults standardUserDefaults] integerForKey:@"bank"]];  
bankTemp = bankTemp + (bankTemp * .10);
[[NSUserDefaults standardUserDefaults] setInteger:bankTemp forKey:@"bank"];

bankTemp would be the $100. I am fairly certain that I’m doing something wrong in the middle line. What can I do to correct it?

EDIT: This is NOT homework. I’m working on a trading game app.

EDIT:

I’ve gotten this far now:

        NSNumber *bankTemp = [[NSNumber alloc] initWithInt:[[NSUserDefaults standardUserDefaults] integerForKey:@"bank"]];  
        bankTemp = [bankTemp intValue] * 1.10;
        [[NSUserDefaults standardUserDefaults] setInteger:[bankTemp intValue] forKey:@"bank"];

EDIT:

To deal with cents, I’m… omitting them!

The game does not need them so they are not worth the trouble. integers it is.

I am curious to see what solutions people have to dealing with cents though, so please continue to post your thoughts on cents.

  • 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-15T12:41:02+00:00Added an answer on May 15, 2026 at 12:41 pm

    You don’t want an NSNumber. NSNumber is a class that wraps around the primitive numeric types so you can use them with, for example, Cocoa collections. If you want to do math, you should just use the primitives. Just do:

    NSInteger bankTemp = [[NSUserDefaults standardUserDefaults] integerForKey:@"bank"];  
    bankTemp = bankTemp + bankTemp * 0.10;
    [[NSUserDefaults standardUserDefaults] setInteger:bankTemp forKey:@"bank"];
    

    And for storing money, you need to consider how you want to treat cents. It’s tempting to use floats so you can literally have 5.25 dollars, but floats are imprecise and cause all sorts of problems when comparing for equality and so on, so it’s usually better to store your currency as an integer in the smallest unit possible and divide to get larger denominations. So if you want to store dollars and cents, represent $100.00 as 10000.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simple piece of code: import java.io.*; public class Read { public
I have this simple piece of code: MyObjectContext db = new MyObjectContext(); Person new_person
this is a simple piece of code which is suppose to read n numbers
I've read similar Q/A on SO but this simple piece of JQuery AJAX code
I have this simple piece of code : int a = 1, b =
I have very simple piece of code. The goal is when i input four-digit
I have a simple piece of code: txtRequiredDate.setText(wwDateFormatter.format(todoEntity.getRequiredDate())); txtRequiredDateDay.setText(dayOfWeek(todoEntity.getRequiredDate())); txtDoneDate.setText(wwDateFormatter.format(todoEntity.getDoneDate())); txtDoneDateDay.setText(dayOfWeek(todoEntity.getDoneDate())); Problem is that
consider this baby simple piece of code pg.connect( { user: 'hhope', password: '...', port:
I write a simple piece of code that creates a div and assign it
I have a very simple piece of code and it reads characters from files.

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.