marzapower/MPNumericTextField

Is Decimal Working?

Closed this issue · 2 comments

I tried to have a decimal field. But I found that when I'm inputting, it behaves more like currency. The decimal button on the keypad doesn't seem to do anything, and I implicitly get 2 digits to the right of the decimal point. I noticed the following

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
...
case MPNumericTextFieldCurrency:
    n = [MPFormatterUtils currencyFromString:fxText.encodedValue locale:locale];
    mul = pow(10, [currencyFormatter maximumFractionDigits] + 1);
    n = @(round(([n doubleValue] * mul))/10);
    break;
case MPNumericTextFieldDecimal:
    n = [MPFormatterUtils numberFromString:fxText.encodedValue locale:locale];
    mul = pow(10, [currencyFormatter maximumFractionDigits] + 1);
    n = @(round(([n doubleValue] * mul))/10);
    break;
...

It's just a dart throw, but the second case looks more like the case than I would suspect it should. Either way, I'm not sure what is meant by "decimal mode", but what it does is definitely not what I expected.

You use MPNumericTextFieldDecimal when you want to insert simple floating point values, eg 13.44, and you use MPNumericTextFieldCurrency when you want to insert floating point values interpreted as currencies.
In both cases the component presumes you will be using a standard 2-decimal-digit number and will handle the value representation automatically. Eg. you type 14596 and you get $145.96 (MPNumericTextFieldCurrency) or simply 145.96 (MPNumericTextFieldDecimal).

This component was originally born to type currencies and percentages, and the "decimal" format is a plus over those two. When inserting currencies and percentages having the decimal digits handled that way (= you don't have to type the divider, but it gets placed on your behalf by the text field) was the most common and accepted way of doing it, so I decided to go that way.

So, yes, this text field correctly handles the MPNumericTextFieldDecimal format as well as the other two. If you feel like this is not true, please give me a way to reproduce your issue and I will be more than happy to help you.

Closing this issue since there are no updates.