CaioQuirinoMedeiros / react-native-mask-input

🎭:iphone: A simple and effective Text Input with mask for ReactNative on iOS and Android. Includes obfuscation characters feature.
https://www.npmjs.com/package/react-native-mask-input
MIT License
309 stars 31 forks source link

Masks.BRL_CURRENCY begin in 0,01 #35

Closed rodrigomoraes closed 1 year ago

rodrigomoraes commented 1 year ago

Have anyway to use Masks.BRL_CURRENCY begin in Centavos and not in Real? Actually if we type 1, it format to R$ 1, in my case should be R$ 0,01

CaioQuirinoMedeiros commented 1 year ago

No. You should try https://github.com/CaioQuirinoMedeiros/react-native-currency-input

rodrigomoraes commented 1 year ago

Oh, i didn't know about this solution... Anyway i do this to solve my problem

const formatAmountToCents = (value: any)  => {
    const amountFormated = (value / 100).toFixed(2).replace(".", "");
    return amountFormated;
  };

  <MaskInput 
      placeholder="R$ 0,00"
      mask={Masks.BRL_CURRENCY}
      value={formatAmountToCents(amount)}
          onChangeText={(masked, unmasked) => {
             setAmount(unmasked);
       }}
  />

And It Works! But i thank you to show me the real solution...