8

Some iOS devices seems to be showing a , (comma) instead of a . on the decimal-pad. I believe this is to do with the keyboard language / locale. Is there a way I can force the decimal-pad to show a . regardless of keyboard language / locale?

<TextInput
    rejectResponderTermination={false}
    style={[
        {
            fontSize: entryValueFontSize,
            height: height,
        },
        calculatorStyles.inputsShared,
        calculatorStyles.amountInput,
        theme.inputsShared,
    ]}
    autoCapitalize={'none'}
    placeholder={entryValueLabel}
    placeholderTextColor={theme.placeholderTextColor}
    keyboardType={'decimal-pad'}
    returnKeyType={'done'}
    defaultValue={''}
    value={isNaN(this.state.entryValue) ? '' : this.state.entryValue}
    onChangeText={(entryValue) => {
        this.onEntryValueChange(entryValue);
    }}
/>

Problem:

enter image description here

Desired output:

enter image description here

Abdul Sadik Yalcin
  • 1,744
  • 2
  • 19
  • 50

1 Answers1

7

It is not possible to force keyboard to use comma. It is based on Region for example Czechia has comma. The solution I have created is to replace comma for decimal with point once comma is entered

<TextInput
  onChangeText={(entryValue) => {
    // I am passing keyboardType as prop
    if (keyboardType === 'decimal-pad') {
      this.onEntryValueChange(entryValue.replace(',', '.'));
    } else {
      this.onEntryValueChange(entryValue);
    }
  }}
/>
Black
  • 9,541
  • 3
  • 54
  • 54
  • Ye that's what I'm doing but this is annoying when working with numbers. I'm going to end up implementing a visual keyboard. – Abdul Sadik Yalcin Oct 07 '21 at 13:39
  • IMO- this happens because the phone is set to an EU location. where people use (comma) instead of (dot) ex: 1.234,56 (EU style) while rest use 1,234.56 – Abhishek Ekaanth Feb 14 '22 at 13:35
  • 1
    @AbhishekEkaanth there is not reason to guess. You can easily find this information where a comma "," or dot "." is used as decimal separator https://en.wikipedia.org/wiki/Decimal_separator#Usage_worldwide – Black Feb 14 '22 at 21:30