Examples of currency calculations for iOS development

Source: Internet
Author: User


When the payment is made and the amount is paid, the price requirement is very strict.
A way to put an amount of arithmetic


Amount Calculation method
typedef enum {
adding,
subtracting,
Multiplying,
Dividing,
}calucateway;

#pragma mark currency calculation
+ (NSString *) Decimalnumbercalucate: (NSString *) originValue1 originValue2: (NSString *) originValue2 Calucateway: ( Calucateway) Calucateway
{
Nsdecimalnumber *decimalnumber1 = [Nsdecimalnumber decimalnumberwithstring:originvalue1];
Nsdecimalnumber *decimalnumber2 = [Nsdecimalnumber decimalnumberwithstring:originvalue2];
Nsdecimalnumber *product;
Switch (calucateway) {
Case adding:
NSLog (@ "+++++++++");
Product = [DecimalNumber1 decimalnumberbyadding:decimalnumber2];
Break

Case subtracting:
NSLog (@ "---------");
Product = [DecimalNumber1 decimalnumberbysubtracting:decimalnumber2];
Break

Case Multiplying:
NSLog (@ "*********");
Product = [DecimalNumber1 decimalnumberbymultiplyingby:decimalnumber2];
Break

Case dividing:
NSLog (@ "/////////");
Product = [DecimalNumber1 decimalnumberbydividingby:decimalnumber2];
Break

Default
Break
}
return [Product StringValue];
}

The above is just the method, the following demo, you can run the test directly

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.