ios-Amount lowercase to uppercase

Source: Internet
Author: User

I. Purpose

1. The amount lowercase is converted to uppercase. such as 123456.65---one pick-up of the Wan Lu Yuanlu Point Wu

2. Only 13-digit amounts can be processed, and only two digits after the decimal point can be processed.

Two. Code

#import "ViewController.h"

#define ScreenWidth [UIScreen mainscreen].bounds.size.width

#define ScreenHeight [UIScreen mainscreen].bounds.size.height

@interface Viewcontroller ()

@property (nonatomic, Strong) UILabel * Smalllabel; Show lowercase Amounts

@property (nonatomic, Strong) UILabel * Biglabel; Show uppercase Amounts

@end

@implementation Viewcontroller

-(void) viewdidload

{

[Super Viewdidload];

[Self initui];

}

-(void) Initui

{

NSString * Money = @ "123456.65";

Self.smalllabel = [[UILabel alloc] init];

Self.smallLabel.frame = CGRectMake (ScreenWidth-20, 40);

Self.smallLabel.text = money;

Self.smallLabel.textAlignment = Nstextalignmentcenter;

[Self.view AddSubview:self.smallLabel];

Capital

Self.biglabel = [[UILabel alloc] init];

Self.bigLabel.frame = CGRectMake (ScreenWidth-20, 40);

Self.bigLabel.text = [self Changetobigmoney:money];

Self.bigLabel.textAlignment = Nstextalignmentcenter;

[Self.view AddSubview:self.bigLabel];

}

The method of the package can be copied directly

#pragma mark Gold-size-and-package method

-(NSString *) Changetobigmoney: (NSString *) numstr

{

Convert to double type

Double numberals = [Numstr doublevalue];

Nsarray *numberchar = @[@ "0", @ "one", @ "II", @ "three", @ "Restaurant", @ "WU", @ "land", @ "Qi", @ "ba", @ "JIU"];

Nsarray *inunitchar = @[@ "", @ "pick", @ "Bai", @ "thousand"];

Nsarray *unitname = @[@ "", @ "Million", @ "Million", @ "trillion"];

Amount multiplied by 100 to convert to a string (to remove rounded points)

NSString *valstr=[nsstring stringwithformat:@ "%.2f", numberals];

NSLog (@ "VALSTR:%@", VALSTR);

NSString *prefix;

NSString *suffix;

NSLog (@ "%lu", (unsigned long) valstr.length);

if (valstr.length <= 2)

{

[email protected] "0 yuan";

if (Valstr.length = = 0)

{

[Email protected] "Certer";

}

else if (valstr.length = = 1)

{

Suffix=[nsstring stringwithformat:@ "%@ min", [Numberchar objectatindex:[valstr Intvalue]];

}

Else

{

NSString *head = [Valstr substringtoindex:1];

NSString *foot = [Valstr substringfromindex:1];

Suffix=[nsstring stringwithformat:@ "%@ corner%@", [Numberchar objectatindex:[head Intvalue]],[numberchar objectAtIndex:[ Foot Intvalue]];

}

}

Else

{

[Email protected] "";

[Email protected] "";

int flag = (int) valstr.length-2;

NSLog (@ "flag:%d", flag);

NSString *head = [Valstr substringtoindex:flag-1];

NSLog (@ "head:%@", head);

NSString *foot = [Valstr Substringfromindex:flag];

NSLog (@ "Foot:%@", foot);

if (head.length>13)

{

return @ "value is too large (maximum 13-bit integer supported), cannot be processed";

}

Processing integral parts

Nsmutablearray * ch = [[Nsmutablearray alloc]init];

for (int i = 0; i < head.length; i++)

{

NSLog (@ "head[i]:%hu", [head characteratindex:i]);

NSString * str=[nsstring stringwithformat:@ "%x", [head characteratindex:i]-' 0 '];

[Ch ADDOBJECT:STR];

NSLog (@ "ch:%@", ch);

}

NSLog (@ "Ch_all:%@", ch);

int zeronum = 0;

NSLog (@ "Ch.count:%ld", Ch.count);

for (int i = 0; i < Ch.count; i++)

{

int index = (ch.count-i-1)% 4;//position within segment

NSLog (@ "index:%d", index);

int indexloc = (int) (Ch.count-i-1)/4;//take segment position

NSLog (@ "Indexloc:%d", indexloc);

NSLog (@ "ch[i]:%@", [ch objectatindex:i]);

if ([[Ch objectatindex:i] isequaltostring:@ "0"])

{

zeronum++;

}

Else

{

if (zeronum! = 0)

{

if (Index! = 3)

{

Prefix=[prefix stringbyappendingstring:@ "0"];

}

Zeronum = 0;

}

prefix = [prefix Stringbyappendingstring:[numberchar objectatindex:[[ch Objectatindex:i]intvalue]];

prefix = [prefix stringbyappendingstring:[inunitchar objectatindex:index]];

}

if (index = = 0 && zeronum < 4)

{

Prefix=[prefix Stringbyappendingstring:[unitname Objectatindex:indexloc]];

}

}

prefix = [prefix stringbyappendingstring:@ "Yuan"];

Working with decimal digits

if ([Foot isequaltostring:@ "00"])

{

Suffix =[suffix stringbyappendingstring:@ "whole"];

}

else if ([foot hasprefix:@ "0"])

{

NSString * footch=[nsstring stringwithformat:@ "%x", [foot characteratindex:1]-' 0 '];

suffix = [nsstring stringwithformat:@ "%@ min", [Numberchar Objectatindex:[footch Intvalue]];

}

Else

{

NSString * headch=[nsstring stringwithformat:@ "%x", [foot characteratindex:0]-' 0 '];

NSString * footch=[nsstring stringwithformat:@ "%x", [foot characteratindex:1]-' 0 '];

suffix = [nsstring stringwithformat:@ "%@ angle%@ min", [Numberchar objectatindex:[headch Intvalue]],[numberchar ObjectAtIndex : [Footch Intvalue]];

}

}

return [prefix Stringbyappendingstring:suffix];

}

@end

ios-Amount lowercase to uppercase

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.