Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Detect whether number is a float/integer?
I need to detect whether a number entered by the user is an integer or a float. If the number is an integer, I will just round to 1dp however if it is a float, I will round to 3dp.
I know how to do the rounding, it's just detecting the integer/float in the first place that I'm stuck with.
Thanks
0 •
Replies
The Predictor: College Basketball
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeTo make that approach portable, you will need to figure out what the decimal separator character is in the current locale. I don't know how to do that off the top of my head, but there should be a way. After a brief search, it looks like you can query the current locale for it's kCFLocaleDecimalSeparator value using the method CFLocaleGetValue.
You can compare the value to it's rounded/truncated value:
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNSString *aString;
NSString *string = @".";
NSRange r = [aTextField.text rangeOfString:string];
NSString *string1 = @",";
NSRange s = [aTextField.text rangeOfString:string1];
if (r.location != NSNotFound | s.location != NSNotFound) {
NSLog(@"a Float");
aString = [NSString stringWithFormat:@"%.1fx²", aInt];
}
else {
NSLog(@"a Integer");
aString = [NSString stringWithFormat:@"%.0fx²", aInt];
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNSLog(@"%.2g", 1.000000);
NSLog(@"%.2g", 1.123456789);
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome