开发者

Variable number formatter in text field

开发者 https://www.devze.com 2023-01-26 22:18 出处:网络
I want to insert a number into a Text Field. If the is larger then 0.001 the number should be displayed as 1.234 (0.000).

I want to insert a number into a Text Field.

If the is larger then 0.001 the number should be displayed as 1.234 (0.000). If the is smaller then 0.001 the number should be displayed as 1.234E-5 (0.000E+0).

I had a look in "LOCALE DATA MARKUP LANGUAGE (LDML)" using Choice Pat开发者_开发技巧terns but this seems not to work from Interface Builder.

How can I do this?


NSNumberFormatter doesn't work for you?


Try this on "changes ended" or whatever it is on the Mac.

- (IBAction) checkFloat: (id)sender
{
    double test = [sender doubleValue];
    if (test > 0.001)
        [sender setStringValue:[NSString stringWithFormat:@"%E",test];

    // etc.

}

Look up string formats here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号