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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:35:12+00:00 2026-06-15T20:35:12+00:00

I’ve seen a similar topic about this a while back, but that seemed to

  • 0

I’ve seen a similar topic about this a while back, but that seemed to be because the equation used NSNumber somewhere. I’ve checked all my code and all I can see is that I’m using NSDecimalNumbers for my equations.

I got a JSON webservice that returns some pricing numbers.

Just after parsing them in object properties I want to run the following equation with them:

NetPrice * ( 1 + (RawPercentage / 100)) + FixedPrice = processedNetPrice

Update:
I changed the code to this:

    NSDecimalNumber *one = [NSDecimalNumber one];

    if (!self.netPrice || [self.netPrice isKindOfClass:[NSNull class]]) 
    { self.netPrice = [NSDecimalNumber zero]; }

    NSDecimalNumber *nettoPrijs = self.netPrice;
    NSLog(@"self.netPrice = %@",self.netPrice);
    //Returns: self.netPrice = 89.25

    NSLog(@"nettoPrijs = %@",nettoPrijs);
    //Returns: nettoPrijs = 89.25

    if (!self.userData.BandFixed || [self.userData.BandFixed isKindOfClass:[NSNull class]]) 
    { self.userData.BandFixed = [NSDecimalNumber zero]; }

    NSDecimalNumber *fixedPrice = self.userData.BandFixed;

    NSLog(@"self.userData.BandFixed = %@",self.userData.BandFixed);
    //Returns: self.userData.BandFixed = 0

    NSLog(@"fixedPrice = %@",fixedPrice);
    //Returns: fixedPrice = 0

    if (!self.userData.BandPercentage || [self.userData.BandPercentage isKindOfClass:[NSNull class]]) 
    { self.userData.BandPercentage = [NSDecimalNumber zero]; }

    NSDecimalNumber *rawPercentage = self.userData.BandPercentage;

    NSLog(@"self.userData.BandPercentage = %@",self.userData.BandPercentage);
    //Returns: self.userData.BandPercentage = 0

    NSLog(@"rawPercentage = %@",rawPercentage);
    //Returns: rawPercentage = 0

    NSDecimalNumber *percentage = [rawPercentage decimalNumberByMultiplyingByPowerOf10:-2];
    NSLog(@"percentage = %@",percentage);
    //Returns: percentage = 0

    NSDecimalNumber *onePercent = [one decimalNumberByAdding:percentage];
    NSLog(@"onePercent = %@",onePercent);
    //Returns: onePercent = 1

    NSDecimalNumber *onePercentTimesNetPrice = [onePercent decimalNumberByMultiplyingBy:nettoPrijs];
    NSLog(@"onePercentTimesNetPrice = %@",onePercentTimesNetPrice);
    //Returns: onePercentTimesNetPrice =        
    -0.000000000000000000000000000000000000000000000000000000000000000000000
    00000000000000000000000000359498933794611654993903616

    NSDecimalNumber *addingFixed = [onePercentTimesNetPrice decimalNumberByAdding:fixedPrice];
    NSLog(@"addingFixed = %@",addingFixed);
    //Returns: addingFixed =  
    -0.000000000000000000000000000000000000000000000000000000000000000000000
    00000000000000000000000000359498933794611654993903616

If I change:

NSDecimalNumber *onePercentTimesNetPrice = [onePercent decimalNumberByMultiplyingBy:nettoPrijs];

to:

NSDecimalNumber *onePercentTimesNetPrice = [nettoPrijs decimalNumberByMultiplyingBy:onePercent];

it crashes:

-[__NSCFNumber decimalNumberByMultiplyingBy:]: unrecognized selector sent to instance 0x84ad160
  • 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-15T20:35:13+00:00Added an answer on June 15, 2026 at 8:35 pm

    As your NSLog() output shows, self.userData.RawPercentage and self.userData.FixedPrice are nil, i.e. are not allocated + initialized as NSDecimalNumber objects.

    nil cannot be used to represent the decimal number zero!

    In fact, when I try your code,

    NSDecimalNumber *custPrice1 = [oneWithNet decimalNumberByAdding:priceFixed];
    

    crashes because priceFixed is nil.

    So you should check the code where these variables are initialized and make sure that they point to valid NSDecimalNumber objects.


    UPDATE: The error message

    -[__NSCFNumber decimalNumberByMultiplyingBy:]: unrecognized selector sent to instance 0x84ad160
    

    shows that nettoPrijs is a NSNumber object and not a NSDecimalNumber. The following simplified code shows what happens if you try to multiply a NSDecimalNumber with a NSNumber:

    NSDecimalNumber *one = [NSDecimalNumber one];
    id price = [NSNumber numberWithFloat:89.25];
    NSDecimalNumber *product = [one decimalNumberByMultiplyingBy:price];
    NSLog(@"product = %@", product);
    // Output:
    // product = -0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000221166721562906606351581184
    

    (I have no idea why this doesn’t crash or produce some error message.)
    It works correctly if you multiply with a NSDecimalNumber:

    price = [NSDecimalNumber decimalNumberWithString:@"89.25"];
    product = [one decimalNumberByMultiplyingBy:price];
    NSLog(@"product = %@", product);
    // Output:
    // product = 89.25
    

    So I assume that self.netPrice is a NSNumber object which has to be converted to a NSDecimalNumber. The same may apply to the other number objects.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

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.