Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to format the value without leading "$"? #36

Open
valeeum opened this issue Apr 1, 2024 · 1 comment
Open

Possible to format the value without leading "$"? #36

valeeum opened this issue Apr 1, 2024 · 1 comment

Comments

@valeeum
Copy link

valeeum commented Apr 1, 2024

My input component already has a prefix that shows "$". Is there any way to specify to not include it in the MoneyInput label? I know the actual value is numeric and does not include it. Thanks in advanced for your help!

image
@valeeum valeeum changed the title Possible to format the value with leading "$"? Possible to format the value without leading "$"? Apr 1, 2024
@rodrigotbrun
Copy link

Hi

I have a similar input like yours, and I'm not using the formatMoney() method from this package anywhere in my code (I have another method that handles that for other views).. So I've changed a little bit the native side to make the input never add the currency symbol.

here's my patch @inkindcards+react-native-money+1.0.6.patch.

diff --git a/node_modules/@inkindcards/react-native-money/android/src/main/java/com/inkind/RNMoneyInput/RNMoneyInputModule.kt b/node_modules/@inkindcards/react-native-money/android/src/main/java/com/inkind/RNMoneyInput/RNMoneyInputModule.kt
index a6c54ec..9647f6a 100644
--- a/node_modules/@inkindcards/react-native-money/android/src/main/java/com/inkind/RNMoneyInput/RNMoneyInputModule.kt
+++ b/node_modules/@inkindcards/react-native-money/android/src/main/java/com/inkind/RNMoneyInput/RNMoneyInputModule.kt
@@ -107,6 +107,11 @@ open class MoneyMask {
          fun getFormatter(localeIdentifer: String?): NumberFormat {
              val locale = getLocale(localeIdentifer)
              val format: NumberFormat = NumberFormat.getCurrencyInstance(locale)
+             val decimalFormatSymbols: DecimalFormatSymbols =
+                (format as DecimalFormat).getDecimalFormatSymbols()
+             decimalFormatSymbols.currencySymbol = ""
+             (format as DecimalFormat).decimalFormatSymbols = decimalFormatSymbols
+            
              return format
          }
 
diff --git a/node_modules/@inkindcards/react-native-money/ios/MoneyInputDelegate.swift b/node_modules/@inkindcards/react-native-money/ios/MoneyInputDelegate.swift
index 5a8f724..028fbc2 100644
--- a/node_modules/@inkindcards/react-native-money/ios/MoneyInputDelegate.swift
+++ b/node_modules/@inkindcards/react-native-money/ios/MoneyInputDelegate.swift
@@ -181,6 +181,7 @@ class MoneyMask {
         currencyFormatter.usesGroupingSeparator = true
         currencyFormatter.numberStyle = .currency
         currencyFormatter.locale = Locale(identifier: locale)
+        currencyFormatter.currencySymbol = ""
         return currencyFormatter
     }

Thanks to this solution, for the kotlin android side: https://stackoverflow.com/a/8658399/27222173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants