Re: Formatter questions
Re: Formatter questions
- Subject: Re: Formatter questions
- From: James Bucanek <email@hidden>
- Date: Fri, 24 Jun 2005 07:14:24 -0700
Andy Bettis wrote on Friday, June 24, 2005:
>If the date is invalid but fits the format string (e.g. 99/99/99) it
>'fixes' it (in this case to 03/08/99).
<clip>
>I also set up an 'amount' field and added a number formatter with
>9999.99 as the format string. When I type in 9.999 it comes up as
>10.00. Obviously this is no good for an accounting program!
Are you sure the formatter is "fixing" the input, or is this just the round-trip results of taking the users input, make a "best effort" to turn it into its native form (NSDate, NSNumber), then reinterpreting that value using the format you've defined?
Given your example, it strikes me that if you have set a number format of ####.## and you enter 9.999, the formatter could easily create an NSNumber of (float)9.999 and store that internally. When redisplaying the number in the cell, it would take 9.999 and round it up to two decimal places (to conform to your display format) resulting in 10.00. But the value in the cell would still be 9.999. Have you checked the internal value object to see if it's 9.999 or 10.0?
Likewise for the date, if the user entered 01/32/2001 the date parser could easily calculate the numeric offset of the mythical 32nd day of January (or the first day of month #32, depending on your locale), which would be reformatted into 02/01/2001. Since NSDates are simply numeric offsets from the epoc, all NSDates are going to be valid. It doesn't mean they will be agnate to what the user entered.
What it sounds like you want is for the formatter to reject the input if the reformatted value isn't the same as the user input. You might be able to do this by subclassing the NS formatters. Use the underlaying formatter to parse the user input and turn it into a value, then reformat that value back into display string, then parse the reformatted display string back into a value again.
User input > user value > reformatted value > reparsed value
Compare the first and second values. If they are different, then there is non-cosmetic difference between the user input the resulting displayed value.
--
James Bucanek <mailto:email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden