I have a string "1.2345677". I want only "1.23" for further use. how to remove other string. Any Help Thanks.
            Asked
            
        
        
            Active
            
        
            Viewed 1,049 times
        
    -1
            
            
        - 
                    If you mean a string, [check here](http://stackoverflow.com/questions/1612337/objective-c-nsstring-and-substring). If you mean a float, [check here](http://stackoverflow.com/questions/18063721/ios-objective-c-how-to-get-2-decimal-rounded-float-value) – Jamie Taylor Dec 05 '13 at 09:03
 
2 Answers
1
            Like so:
NSString *origString = @"1.2345677";
NSString *subString = [origString substringToIndex:3];
        Thomas Keuleers
        
- 6,075
 - 2
 - 32
 - 35
 
0
            
            
        NSString *mainstr = @"1.2345677";
float conver = [mainstr floatValue];
NSString *floatedstr =[NSString stringWithFormat:@"%.2f",conver];
You can also do it with
NSNumberFormatter *format = [[NSNumberFormatter alloc] init];
[format setFormat:@"0.##"];
NSLog(@"%@", [format stringFromNumber:[NSNumber numberWithFloat:25.342]]);
        Pradhyuman sinh
        
- 3,936
 - 1
 - 23
 - 38