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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:46:14+00:00 2026-06-17T10:46:14+00:00

In my Core Data model, amount is an attribute in entity Tracking. How do

  • 0

In my Core Data model, “amount” is an attribute in entity “Tracking”. How do I convert amount to NSDecimalNumber throughout the code? I’m sure someone with more experience can do this in 3 minutes where I have been looking at it for days.

- (IBAction)save {
if (![amount.text isEqualToString:@""]) {
Tracking *tracking = [NSEntityDescription insertNewObjectForEntityForName:@"Tracking"
                                               inManagedObjectContext:self.managedObjectContext];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *weightEntity = [NSEntityDescription entityForName:@"Tracking" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:weightEntity];
    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:NO];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];

    NSError *error = nil;
    NSArray *result = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];

    Tracking *person = [result objectAtIndex:0];

    NSLog(@"%@",person.date);

        NSDate *date = [NSDate date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"MMM dd, yyyy"];

    NSString *dateString = [dateFormat stringFromDate:date];
    //NSString *dateString = @"Jan 13 2013";
    //Tracking *track = [self.fetchedResultsController objectAtIndexPath:nil];

tracking.note = note.text;
tracking.amount = amount.text;
tracking.title = [segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex];
tracking.date = dateString;
tracking.timestamp = date;

        if (![person.date isEqualToString:dateString]) {

        if ([[segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex] isEqualToString:@"Food/Drink"]) {
            tracking.pic = @"Drink";
            tracking.total = [NSString stringWithFormat:@"%.2f", 0.00 - [amount.text floatValue]];
            NSLog(@"%f",[person.total floatValue]);
            NSLog(@"%f", [amount.text floatValue]);
            //tracking.total = @"1000.00";
        }
        else if ([[segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex] isEqualToString:@"Other"]) {
            tracking.total = [NSString stringWithFormat:@"%.2f",0.00 - [amount.text floatValue]];
            tracking.pic = [segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex];

        }

        else {
            tracking.pic = [segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex];
            tracking.total = [NSString stringWithFormat:@"%.2f",0.00 + [amount.text floatValue]];
        }

    }

    else {


        if ([[segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex] isEqualToString:@"Food/Drink"]) {
            tracking.pic = @"Drink";
            tracking.total = [NSString stringWithFormat:@"%.2f",[person.total floatValue] - [amount.text floatValue]];
            NSLog(@"%f",[person.total floatValue]);
            NSLog(@"%f", [amount.text floatValue]);
    //tracking.total = @"1000.00";
            }
        else if ([[segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex] isEqualToString:@"Other"]) {
            tracking.total = [NSString stringWithFormat:@"%.2f",[person.total floatValue] - [amount.text floatValue]];
            tracking.pic = [segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex];

        }

        else {
            tracking.pic = [segmentedChoice titleForSegmentAtIndex:segmentedChoice.selectedSegmentIndex];
            tracking.total = [NSString stringWithFormat:@"%.2f",[person.total floatValue] + [amount.text floatValue]];

        }
    }

NSLog(@"\n Title: %@ \n Amount: %@ \n Note: %@ \n Date: %@ \n Picture: %@.png \n Total: %@ \n TimeStamp: %@", tracking.title, tracking.amount, tracking.note,tracking.date,tracking.pic, tracking.total, tracking.timestamp);

   [self.managedObjectContext save:nil];

   /* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@ Saved",tracking.title] message:[NSString stringWithFormat:@"Amount: %@ \n Note: %@",tracking.amount,tracking.note] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];*/

    [amount resignFirstResponder];
    [note resignFirstResponder];
    [self dismissViewControllerAnimated:YES completion:nil];
}
  • 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-06-17T10:46:15+00:00Added an answer on June 17, 2026 at 10:46 am

    NSDecimalNumber has following method which you can use to convert your NSString into it:

    + (NSDecimalNumber *)decimalNumberWithString:(NSString *)numericString
    

    For example:

    NSString *foo = @"1.0";
    NSDecimalNumber *cow = [NSDecimalNumber decimalNumberWithString:foo];
    

    Full reference of the class is available here: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDecimalNumber_Class/Reference/Reference.html#//apple_ref/occ/cl/NSDecimalNumber

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

Sidebar

Related Questions

I have a Core Data model similar to this: Company Entity companyName attribute (string)
In my core data model I have a Person entity that has a to
Say I have a core data model with a few entities and, throughout the
I have set up a Core Data model that includes an entity, Item with
I have an expense tracking iOS Application using Core Data Model: Scenario: -> An
My Core Data model contains an entity, Shape, that has two self-referential relationships, which
Given the following Core Data Model: -> : to-one releationship ->>: to-many relationship Entity
I have a Core Data model entity NoteObject that has a transformable type arrayOfTags
I have a core data model which includes an entity with a to-many relationship.
I have a Core Data model setup like so: Blockbuster Entity To-Many relationship to

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.