I'm looking how to transform Array string to Array float, Array string is in format 00:00:00 (hh:mm:ss) and array float is 00.00.00 The reason is because array float Is calculated in a chart For now i only have this
example array
TimeRunning = @[@"01:10:50", @"01:03:23", @"03:04:22"];//arrayStrig
real code is
timeRunning = [obj valueForKey:@"oficialTime"];
NSLog(@"%@",timeRunning); //out 01:02:03 10:10:02 10:38:59
float ofcTime =[[obj valueForKey:@"oficialTime"]floatValue];
NSLog(@"float : %f",ofcTime); //out 1.000000 10.000000 10.000000
I try this
NSString * dataString = [TimeRunningString stringByReplacingOccurrencesOfString:@":" withString:@"."];
NSLog(@"??????: %@",dataString); //out 01.02.03 10.10.02 10.38.59
NSArray *listItems = [dataString componentsSeparatedByString:@"."];
NSLog(@"Real: %@",listItems);//out 10,
10,
02
NSString *covert = [NSString stringWithFormat:@"%@",listItems];
NSLog(@":%@",covert); //out 10,
10,
02
float realArrary = [dataString floatValue];
NSLog(@"floatP : %f",realArrary); out 2.030000 10.000000 10.100000
Try
NSString *dateString = [obj valueForKey:@"oficialTime"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm:ss.SSS"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:dateString];
NSLog(@"%@",dateString); //Out 02:03:03
then
NSString * dataString = [TimeRunningString stringByReplacingOccurrencesOfString:@":" withString:@""]; float Realarrary = [dataString floatValue];
NSLog(@"floatP: %0.0f",Realarrary); //Out 20303
now you have string 02:03:03 to float 20303
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.