Convert Array String to Array float

0

People have a challenge I have to convert arrayString to arrayFloat it's not how you usually do it

 array *date = [obj valueForKey:@"oficialTime"];// por ejemplo 10:10:02
 float f = [date floatValue];

The problem here is that array is in Nsdate format hh: mm: ss

 array *date = [obj valueForKey:@"oficialTime"];
 { 02:03:03  01:02:03  10:10:02 }

When I do the conversion float gives me these values

20000,10000,10000

I have managed and achieved that float gives me the complete values but without separation of the points

Now I have this data

20303,10203,101002,

The problem is that this is a string and I need these values in float but with the separation of the points because I must determine the minutes and seconds but float does not recognize the colon (:) and of course in Array

an array float serai something like this

NSAarrayFloat= @[@2, @3, @4,@5];//float

When I need something like this

NSAarrayFloat= @[@02:03:03, @01:02:03, @01:02:03];//float
    
asked by Yo el mismo 20.01.2017 в 13:12
source

2 answers

1

Make a loop that goes through that string array of yours and convert them one by one to float like this:

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;


float value = [numberFormatter numberFromString:@"32.12"].floatValue;
    
answered by 25.01.2017 в 22:02
1

I recommend working with an arrangement of arrangements. I think you should not work with floats, since the hours do not have floats because they always have this format: "int: int: int"

NSArray<NSString*>* arrayStrings = @[@"02:03:03", @"01:02:03", @"10:10:02"];
NSMutableArray< NSArray<NSNumber*>* > *arrayInts = [NSMutableArray arrayWithCapacity:arrayStrings.count];
for (NSString *s in arrayStrings) {
    NSArray *timeComponentsString = [s componentsSeparatedByString:@":"]; //esto produce un arreglo de strings [@"02", @"03", @"03"]
    NSArray *timeComponentsInt = @[ @([timeComponentsString[0] intValue]), @([timeComponentsString[1] intValue]), @([timeComponentsString[2] intValue]) ]; //esto produce un arreglo de ints [@02, @03, @03]
    [arrayInts addObject: timeComponentsInt];
}

The arrayInts array will be an array of integer arrays, following the example would have these values:

[
[@02, @03, @03],
[@01, @02, @03],
[@10, @10, @02]
]
    
answered by 28.04.2017 в 21:27