Jump to content

Android and entering floating point numbers

Featured Replies

Hello!

 

Android and entering floating point numbers. With inputType=numericDecimal

 

Has anybody found any sensible solution to this madness.. ?

 

Google has not done anything since at least 2009 AFAIK.

 

This for instance

http://stackoverflow.com/questions/12780125/soft-keyboard-with-comma-instead-of-dot-for-decimal-separator-in-android

doesn't work on my Samsung Galaxy S5..

 

Tried

input.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));

and the only thing it did, changed "." (dot) key on keyboard,

to ".-,+", but it's just visual (!),

not having any impact on entered characters in text view field..

(still not able to enter comma character on the phone).

 

The only thing that really works is ignoring "numericDecimal" and going with "text" inputType...

 

Best Regards!

 

ps. If you're UK/USA citizen you will probably have no idea about what I am talking about...

But as you can see on the map (middle of page)

https://en.wikipedia.org/wiki/Decimal_mark

https://en.wikipedia.org/wiki/File:DecimalSeparator.svg

It's affecting at least half of human kind..

 

  • Author

Maybe I should explain a bit to UK/USA members what is happening (although I doubt you can help without even being able to replicate issue):

If we have textView control, with inputType=numeric or inputType=numericDecimal etc,

there is showed special smaller keyboard with just digits,

and dot keys,

so we can enter f.e. 3.141265,

but half of world is using comma as floating point separator, not dot.

 

When using

Double Double.parseDouble( String string );

dot is treated as separator (even if locale is using comma).

(there is exception while trying to parse string with comma, or it's cut in half)

 

When using

String.format( "%f", double );

where is used locale,

to print double.

 

So, if we print double to text, with comma as separator,

and then try to parse it, with dot as separator,

it will obviously screw up float/double.

 

If we try to use

 

 

String string = textView.getText().toString();
try
{
   NumberFormat format = NumberFormat.getInstance();
   Number number = format.parse( string );
   value = number.doubleValue();
}
catch ( NumberFormatException e ) {
}
catch ( ParseException e ) {
}
parsing and printing will be fine, using comma (locale),

but (virtual) keyboard on smartphone (at least mine) is showing digits keys and dot key, and not comma key,

so not being able to enter correct separator character,

and not being able to enter fraction..

Edited by Sensei

A related bizarre shortcoming is the lack of a Japanese keyboard or input method.

 

Despite years of development, Android still looks like something that was put together as a fun project by some interns.

Here in N.Z. I choose UK English as my default. That means I get keyboards with pound signs, not dollar signs.

 

 

 

(I'm a programmer, but all in the Microsoft world and on PC's and servers - never touched Android in that sense. However, I have a friend who does Android for a living and will see if he's got a comment. Except I'm out of town for two weeks so there'll be a delay.)

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.