• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSNumberFormatter scientific notation and fraction digits
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumberFormatter scientific notation and fraction digits


  • Subject: Re: NSNumberFormatter scientific notation and fraction digits
  • From: "email@hidden" <email@hidden>
  • Date: Mon, 28 Feb 2011 11:17:01 +0000

Hi Quincey

Thanks for the reply.

On 27 Feb 2011, at 22:07, Quincey Morris wrote:

> On Feb 27, 2011, at 13:42, email@hidden wrote:
>
>> [self.formatter setMaximumFractionDigits:3];
>> [self.formatter setMinimumFractionDigits:3];
>
> The documentation describes these as affecting "input" to the number formatter, which presumably means strings being interpreted as numbers, and not numbers being formatted as strings.
I would agree.
If you manipulate the NSTextField UI the input is formatted and, if bound, the bound value reflects, precisely, the displayed value.
If you manipulate the model value however, the UI displays the formatted value, but the underlying model value remains unchanged and may differ from the displayed value in terms of precision.

>
>> I also tried call -setMaximumSignificantDigits:4 but this did not seem to improve the situation.
>
> This one does seem to be for output, not input. Did you also 'setUsesSignificantDigits:YES'? It looks like that's necessary.
>
That was the problem. The following now functions as per expectations.

NSInteger _decimalPlaces = 3;
[self.formatter setNumberStyle:NSNumberFormatterScientificStyle];
[self.formatter setMaximumFractionDigits:_decimalPlaces];
[self.formatter setMinimumFractionDigits:_decimalPlaces];
[self.formatter setMaximumSignificantDigits:_decimalPlaces+1];
[self.formatter setMinimumSignificantDigits:_decimalPlaces+1];
[self.formatter setUsesSignificantDigits:YES];

The docs are silent on why this is necessary and what the relationship between NSNumberFormatterScientificStyle, the fraction digits and the significant digits is.

With regard to NSNumberFormatterDecimalStyle setting minimumSignificantDigits = 2 and inputting 12345 produces an output of 10000 - which is not what I would expect.

Can anyone from Apple confirm what the expected behaviour of the significant digits methods is?

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSNumberFormatter scientific notation and fraction digits (From: "email@hidden" <email@hidden>)
 >Re: NSNumberFormatter scientific notation and fraction digits (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: WindowID to front
  • Next by Date: Re: WindowID to front
  • Previous by thread: Re: NSNumberFormatter scientific notation and fraction digits
  • Next by thread: Accessibility in custom NSControl subclasses
  • Index(es):
    • Date
    • Thread