wybot
wybot

Reputation: 345

Xamarin Forms Android keyboard decimal separator

I use this code to convert value:

v = double.Parse(entry1.Text, CultureInfo.InvariantCulture);

in iOS it's all right - I entering 3,2 and it convert it to 3.2

But in Android, I can't enter a dot between numbers - only comma But when I enter 3,2 it converts it to 32! Device language - Russian. Please help me! Thanks!

Upvotes: 1

Views: 875

Answers (2)

wybot
wybot

Reputation: 345

V = double.parse(entry1.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

Upvotes: 1

Arjun Vyas
Arjun Vyas

Reputation: 419

It might be possible that, you have set your view property like as below:

<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number" />

convert android:inputType="number" to android:inputType="numberDecimal"

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal" />

Edited : Or you could try removing comma from the value.

try { 
    doubleValue = Double.parseDouble(s.toString().replace(',', '.')); 
} catch (NumberFormatException e) { 
    //Error 
}

Upvotes: 1

Related Questions