This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 42000 - Unable to use comma (",") as decimal point
Summary: Unable to use comma (",") as decimal point
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.3.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-06-20 15:24 UTC by Andreas
Modified: 2017-07-17 13:35 UTC (History)
9 users (show)

See Also:
Tags: Android ac
Is this bug a regression?: ---
Last known good build:


Attachments
repro solution (268.92 KB, application/zip)
2016-06-22 18:27 UTC, Jimmy
Details

Description Andreas 2016-06-20 15:24:44 UTC
I live in sweden and my phone/app uses Swedish locale (Sv_SE).
What I want is an Entry field for decimal values.

I create an Entry field and set the Keybord to "Numeric". ( <Entry Keyboard="Numeric"/> )

This gives me a numeric keypad with BOTH "," and "." visible. However, pressing "," has no effect. Only the "." is accepted. 

I also tried creating a custom renderer, like suggested here:
https://bugzilla.xamarin.com/show_bug.cgi?id=25373
to set InputType = InputTypes.ClassNumber | InputTypes.NumberFlagSigned | InputTypes.NumberFlagDecimal

However, still only "." was accepted.

The device is a Google/LG Nexus 5 (phone) using Google Keyboard as it's keyboard.

Since my users here in sweden are used to write one and a half like "1,5" they will end up Writing "15" since the "," is ignored. This is NOT OK!

Please don't suggest to use
KeyListener = DigitsKeyListener.GetInstance("-0123456789,")
since this will force _me_ to check for valid decimal values (the user might otherwice write things like "3,5,4,3,,,9")
Comment 1 Jimmy 2016-06-22 18:27:10 UTC
Created attachment 16444 [details]
repro solution

I think the issue is more general: the ‘,’ and ‘-‘ characters on the numeric keyboard are not inputted regardless of the system language. I’ve attached a repro project that demonstrates this.

### Steps to Reproduce 
1. Run the Android project
2. Attempt to enter a comma in the Entry 


### Workaround
A workaround is to use a custom Entry renderer and use:

> KeyListener = DigitsKeyListener.GetInstance("-0123456789,")

If the Entry is bound to a double, the value entered should be parsed automatically to prevent multiple ‘,’ characters. However there is another bug affecting this (bug#42084). But there is a workaround for that issue as well provided in the report.
Comment 2 adrianknight89 2016-09-30 02:42:11 UTC
See https://github.com/xamarin/Xamarin.Forms/pull/396

Andreas, I talked about the way to validate the text. I don't believe the keyboard should be responsible for data validation. To you, 3,5,4,3,,,9 might be incorrect behavior, but there are many ways to represent numbers internationally and custom logic can be required to generate custom patterns.
Comment 3 Rui Marinho 2017-02-17 11:18:23 UTC
Should be fixed in 2.3.5-pre1
Comment 4 Lars 2017-05-26 10:13:17 UTC
Tested in 2.3.5.239-pre3 and it does work. However, the solution provided is not very user friendly. The button that previously showed a period "." now displays ".-,+" instead. Users will then have to triple click that button every time they want to write a comma.

This might be ok, if you only have to use it once in a while, but when regularly having to input multiple numbers this quickly becomes cumbersome.

In my opinion, there should be a separate column for these symbols on the numeric keyboard, or at least the comma should be placed first on locales that use comma as decimal separator, so the user only have to press the button once.
Comment 5 E.Z. Hart 2017-05-27 02:00:55 UTC
(In reply to Lars from comment #4)
> Tested in 2.3.5.239-pre3 and it does work. However, the solution provided is
> not very user friendly. The button that previously showed a period "." now
> displays ".-,+" instead. Users will then have to triple click that button
> every time they want to write a comma.
> 
> This might be ok, if you only have to use it once in a while, but when
> regularly having to input multiple numbers this quickly becomes cumbersome.
> 
> In my opinion, there should be a separate column for these symbols on the
> numeric keyboard, or at least the comma should be placed first on locales
> that use comma as decimal separator, so the user only have to press the
> button once.

Lars,

I just fired up my emulator and I don't see a button with ".-,+"; I see a "," button and a separate button for ".". So this might be an issue for specific devices or API levels that we overlooked. What device and version of Android are you seeing this behavior on?
Comment 6 Lars 2017-05-27 15:20:39 UTC
The app we are making is primarily for use on tabs, but I have also tested it on my phone. I get the same issue on both devices.

Tab: Samsung Galaxy Tab Active 8.0" 16GB (OS: Android 5.1.1)
Phone: Samsung Galaxy S6 (OS: Android 7.0)

I have now tested on an emulator as well and I can see that you are right. There is a separate comma button there. So it could be that this is a problem that only affects Samsung devices.
Comment 7 Ivan 2017-07-05 13:51:24 UTC
Hi. Xamarin Forms version is 2.3.5.255-pre5. No matter Entry is bound to decimal or string property, Numeric keyboard allows only dot input. Tried with English and German language on phone. Even tried forcing German locale in app.
Then, in native Xamarin Android, tried this approach:
Used EditText with following attributes:
<EditText
    android:id="@+id/numericInput"
    android:inputType="numberDecimal"
    android:digits="0123456789.,"/> 
Then EditText opened numeric keyboard, and both dot and comma inputs were allowed and shown both in keyboard and edittext.
Then, in Forms, made custom Entry renderer with:
Control.InputType = InputTypes.NumberFlagDecimal;
Control.KeyListener = DigitsKeyListener.GetInstance("1234567890.,"); 
(Entry bound to string property, trying to simualete edittext setting explained above).
Comma is accepted in this way:
When it is typed, keyboard does not show it
e.g. 23,3, keyboard shows 233
After keyboard is closed, entry has 23,3 inside.
Is there any way this can be fixed? Thanks.
Comment 12 Jimmy 2017-07-12 15:52:48 UTC
@Ivan The issue you are describing sounds like bug 42084 instead. That issue appears to still be occurring in 2.3.5.
Comment 13 Saurabh Paunikar 2017-07-17 07:04:17 UTC
Verified on xamarin.form version 2.3.5.256-pre6.

ScreenCast link : https://www.screencast.com/t/haxZhsozVF

Note: Language of emulator in screencast is Svenska
Comment 14 Ivan 2017-07-17 12:30:51 UTC
@Saurabh Still numeric keyboard only allows dot, not comma (when press comma, nothing happens, input is not accepted).
Info: Emulator runs on Android 5.1 - API 22, language set to Svenska, and entry defined in XAML like:
<Entry Grid.Row="0" Grid.Column="1" Margin="5,0,5,0" Text="{Binding BookingValue}" HorizontalOptions="Start" WidthRequest="100" HorizontalTextAlignment="End" Keyboard="Numeric"/>
where BookingValue is decimal type. 
From packages.config:
<package id="Xamarin.Forms" version="2.3.5.256-pre6" targetFramework="portable45-net45+win8" />
Tried the same with my phone which runs on 5.1.1. Results are the same. Also on Android 6 emulator. Even if Entry is boung to string property.
Please give more info so I can try again, like how your entry control looks like in XAML, etc.
Comment 15 Saurabh Paunikar 2017-07-17 12:43:46 UTC
(In reply to Ivan from comment #14)
> @Saurabh Still numeric keyboard only allows dot, not comma (when press
> comma, nothing happens, input is not accepted).
> Info: Emulator runs on Android 5.1 - API 22, language set to Svenska, and
> entry defined in XAML like:
> <Entry Grid.Row="0" Grid.Column="1" Margin="5,0,5,0" Text="{Binding
> BookingValue}" HorizontalOptions="Start" WidthRequest="100"
> HorizontalTextAlignment="End" Keyboard="Numeric"/>
> where BookingValue is decimal type. 
> From packages.config:
> <package id="Xamarin.Forms" version="2.3.5.256-pre6"
> targetFramework="portable45-net45+win8" />
> Tried the same with my phone which runs on 5.1.1. Results are the same. Also
> on Android 6 emulator. Even if Entry is boung to string property.
> Please give more info so I can try again, like how your entry control looks
> like in XAML, etc.

When you change your emulator language to Svenska, it allows comma. Please see attached screenCast : https://www.screencast.com/t/haxZhsozVF
Comment 16 Ivan 2017-07-17 12:49:09 UTC
@Saurabh Sorry, it does not. That is why I asked you for more details.
Comment 17 Saurabh Paunikar 2017-07-17 12:57:33 UTC
@Ivan I have used attached project
Comment 18 Ivan 2017-07-17 13:35:00 UTC
@Saurabh Got it. So, I have downloaded solution, upgraded Xamarin Forms to pre6, and it still does not work on Emulator 5.1 and 6... Do not understand what can be the issue...

Note You need to log in before you can comment on or make changes to this bug.