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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:15:19+00:00 2026-06-07T22:15:19+00:00

I know this kind of question shouldn’t be asked. But, I stuck here for

  • 0

I know this kind of question shouldn’t be asked. But, I stuck here for days without any clue. So, I really need help.

I have a core data object, let’s say, products.

// Product
NSDecimalNumber *quantity
NSDecimalNumber *price

What I’m trying to do is summarize the price and set it to a label. I search and found some topic here said that NSDecimalNumber can’t do standard match operation as it’s an object that wrap the actual value. It has to be done through decimalNumberByAdding and decimalNumberByMultiplyingBy. So, I wrote the following code,

NSDecimalNumber *totalPrice = [[NSDecimalNumber alloc] initWithDouble:0.0];
[self.productArray enumerateObjectsUsingBlock:^(Product *product, NSUInteger idx, BOOL *stop) {
    [totalPrice decimalNumberByAdding:[product.price decimalNumberByMultiplyingBy:product.quantity]];
    NSLog(@"%@", totalPrice);
    NSLog(@"%@", totalPrice.doubleValue);
    NSLog(@"%@", totalPrice.decimalValue);
}];

None of those NSLog were showing correct result. They were showing neither 0 or NULL

But, if I NSLog the following code, the correct result can be shown.

[product.price decimalNumberByMultiplyingBy:product.quantity]

Can you help me point out what do I miss here?

  • 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-07T22:15:22+00:00Added an answer on June 7, 2026 at 10:15 pm

    You are not assigning the return value.

    [totalPrice decimalNumberByAdding:[product.price decimalNumberByMultiplyingBy:product.quantity]];
    

    should be:

    totalPrice = [totalPrice decimalNumberByAdding:[product.price decimalNumberByMultiplyingBy:product.quantity]];
    

    Since decimalNumberByAdding returns a value, does not update the variable automatically. Because of that, totalPrice is always 0, that’s the value you assigned on init.

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

Sidebar

Related Questions

I know this type of question has been asked a lot, but I really
I know this kind of question has been asked before, for example here: Android:
I know this is kind of a dumb question, but does anyone have an
I know this is probably a question that is asked a ton on here
I know this isn't a straightforward question but I would really appreciate some feedback
I'm not sure if it's ok to ask this kind of question here, but
I know this question has been kind of asked and have looked into the
I know this question has kind-a started religious wars in past and there might
I know this kind of questions have been asked already many times before. The
I know that this kind of issue is most discussed. But I would like

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.