//数値のフォーマット
NSNumber *number = [NSNumber numberWithFloat:4321.1234];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setPositiveFormat:@"#,##0.0"];
NSString *numberStr = [formatter stringFromNumber:number];
//uintを先頭ゼロ付きHex文字列にする場合
NSString *hexStr = [NSString stringWithFormat:@"%8X", hexNum];
//多言語対応
//NSNumberFormatterはLocaleに合わせた変換を行う
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setPositiveFormat:@"0.0"];
//currentLocale以外の場合に設定
//[formatter setLocale:anNSLocale ];
NSString *str = [formatter stringFromNumber:anNSNumber];
//NSStringを数値に変換する場合に注意
//小数点が","のLocalの場合
[@"1,0" floatValue] => 1.100000
[@"1,1" floatValue] => 1.000000
//NSDecimalNumberを使用すると正しい変換ができる
[NSDecimalNumber decimalNumberWithString:@"1.1" locale:NSLocale.currentLocale]; => 1
[NSDecimalNumber decimalNumberWithString:@"1,1" locale:NSLocale.currentLocale]; => 1.1
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy年MM月dd日"];
NSString *dateStr = [dateFormatter stringFromDate:_date];
//多言語対応
NSDateFormatter *dateFormatter =
[NSDateFormatter localizedStringFromDate:date
dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterShortStyle];
//3ヶ月前の日付に設定する。NSDate *date = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *componentss =
[calendar components:(NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:date];
[componentss setMonth:[comps month] - 3];
0 件のコメント:
コメントを投稿