rangeofstring

张工 2022-05-20 20:35:02 阅读:94
  

  iOS‘—

iOS  ‘—

  应用程序———

  0 - 0.00

  123 - 123.00

  123.456 - 123.46

  102000 - 102,000.00

  10204500 - 10,204,500.00

  ”———

  ' "

  … .…— ' .00 '" — '…— ,

  -(ns string *)货币格式:(ns string *)货币{

  如果(!money || money.length==0) {

  还钱;

  }

  BOOL hasPoint=NO

  if ([money rangeOfString:@ ' . '].长度0) {

  hasPoint=是

  }

  NSMutableString * point money=[NSMutableString string with string : money];

  if (hasPoint==NO) {

  【点钱appendstring : @。00 '];

  }

  NSArray * money=[由字符串: @ ',']分隔的点数货币成分;

  如果(钱。计数2){

  返还积分钱;

  } else if (moneys.count==1) {

  返回格式为: @ ' % @的[ns string字符串。00 ',钱[0]];

  }否则{

  // " 3 '…—

  ns string * front money=[self stringformatorethebit : money[0]];

  如果([前面的钱等于字符串: @ ' ']){

  frontMoney=@ ' 0

  }

  //'

  ns字符串*退钱=钱s[1];

  如果([返款长度]==1) {

  返回[ns string字符串,格式为: @ @ ' % @ .%@0 ',前钱,后钱];

  } else if ([backMoney length] 2) {

  返回[ns string字符串,格式为: @ @ ' % @ .“%@”、frontMoney、[back money子串索引:2]];

  }否则{

  返回[ns string字符串,格式为: @ @ ' % @ .%@ ',前钱,后钱];

  }

  }

  }

/p>

  

  …stringFormatToThreeBit: –°

  

  - (NSString *)stringFormatToThreeBit:(NSString *)string {

  

  NSString *tempString = [string stringByReplacingOccurrencesOfString:@"," withString:@""];

  

  NSMutableString *mutableString = [NSMutableString stringWithString:tempString];

  

  NSInteger n = 2;

  

  for (NSInteger i = tempString.length - 3; i > 0; i--) {

  

  n++;

  

  if (n == 3) {

  

  [mutableString insertString:@"," atIndex:i];

  

  n = 0;

  

  }

  

  }

  

  return mutableString;

  

  }

  

  è°°è·é …è NSNumberFormatter ”¨¤ NSString ’ NSNumber é—è–è°—–‘éèè NSNumberFormatter numberStyle ’ positiveFormat ±§°è°èé

  

  - (NSString *)formatDecimalNumber:(NSString *)string {

  

  if (!string || string.length == 0) {

  

  return string;

  

  }

  

  NSNumber *number = @([string doubleValue]);

  

  NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];

  

  formatter.numberStyle = kCFNumberFormatterDecimalStyle;

  

  formatter.positiveFormat = @"###,##0.00";

  

  NSString *amountString = [formatter stringFromNumber:number];

  

  return amountString;

  

  }

  

  —é§è…NSNumberFormatter’”¨

  

  NSNumberFormatter”¨¤NSString’NSNumberé—è–è°—è–

  

  1”¨+ localizedStringFromNumber:numberStyle:°–––NSNumber°NSString

  

  · è”…°°

  

  NSNumber *number = @(123423.5563);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterNoStyle];

  

  // 123424

  

  · 觰—

  

  NSNumber *number = @(12342323.5563);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterDecimalStyle];

  

  // 12,342,323.556

  

  · 觰–觷

  

  NSNumber *number = @(12342323.5563);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterCurrencyStyle];

  

  // 12,342,323.56

  

  · °,”è”…°”°é¨

  

  NSNumber *number = @(12342323.5563);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterPercentStyle];

  

  // 1,234,232,356%

  

  · §‘è°

  

  NSNumber *number = @(12342323.55665); NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterScientificStyle];

  

  // 1.234232355665E7

  

  · °–

  

  NSNumber *number = @(12342323.55665);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterSpellOutStyle];

  

  // ‰‰‰””……”

  

  · °

  

  NSNumber *number = @(12342323.55665);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterOrdinalStyle];

  

  // 1234,2324

  

  · è§ ¤ISOé…觷

  

  NSNumber *number = @(12342323.55665);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterCurrencyISOCodeStyle];

  

  // CNY12,342,323.56

  

  · è§

  

  NSNumber *number = @(12342323.55665);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterCurrencyPluralStyle];

  

  // 12,342,323.56°‘

  

  · è

  

  NSNumber *number = @(12342323.55665);

  

  NSString *numStr1 = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterCurrencyAccountingStyle];

  

  // 12,342,323.56

  

  2§–NSNumberFormatterè±”¨- (NSNumber *)numberFromString:(NSString *)string;–NSNumber°NSString

  

  · ·(numStyle)éè¤(NSNumberFormatterNoStyle)è”…,…–·1‰

  

  NSNumber *number = @(12342323.55665);

  

  NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];

  

  // 觷

  

  formatter.numberStyle = NSNumberFormatterDecimalStyle;

  

  // 艷

  

  [formatter setPositiveFormat:@"###0.###"];

  

  // °—é—é”

  

  [formatter setDecimalSeparator:@":"];

  

  [formatter setCurrencyDecimalSeparator:@","];

  

  // ‰·

  

  formatter.positivePrefix = @"!";

  

  // ·

  

  formatter.positiveSuffix = @"…";

  

  // é—é··

  

  formatter.paddingCharacter = @"?";

  

  //

  

  formatter.formatWidth = 15;

  

  // °‘±¤¤°°

  

  formatter.minimumFractionDigits = 2;

  

  // ¤±¤‰°

  

  formatter.maximumIntegerDigits = 5;

  

  NSString *numStr = [formatter stringFromNumber:number];

  

  // ??????!323:557…

  

  · ”·±¤

  

  NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];

  

  [numberFormatter setPositiveFormat:@"0.00%;0.00%;-0.00%"];

  

  NSLog(@"%@", [numberFormatter stringFromNumber:@4.0]);

  

  // Output: "400.00%".

  

  // °–

  

  NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];

  

  [numberFormatter setNumberStyle:NSNumberFormatterPercentStyle];

  

  NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];[numberFormatter setLocale:usLocale];

  

  NSLog(@"en_US: %@", [numberFormatter stringFromNumber:@4.0]);

  

  // Output: "en_US: 400%".

  

  NSLocale *faLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"fa_IR"];

  

  [numberFormatter setLocale:faLocale];

  

  NSLog(@"fa_IR: %@", [numberFormatter stringFromNumber:@4.0]);

  

  // Output: "fa_IR: °°."

  

  –°è‰éèé—§è…

二维码