@Test public void testTruncateAndConvertDecimalString() { assertEquals(Utils.truncateAndConvertDecimalString("10.12345678", 8), "10.12345678"); assertEquals(Utils.truncateAndConvertDecimalString("5", 8), "5"); assertEquals(Utils.truncateAndConvertDecimalString("5", 0), "5"); assertEquals(Utils.truncateAndConvertDecimalString("0.123", 4), "0.123"); assertEquals(Utils.truncateAndConvertDecimalString("0.123", 3), "0.123"); assertEquals(Utils.truncateAndConvertDecimalString("0.123", 2), "0.12"); assertEquals(Utils.truncateAndConvertDecimalString("0.123", 1), "0.1"); assertEquals(Utils.truncateAndConvertDecimalString("0.123", 0), "0"); assertEquals(Utils.truncateAndConvertDecimalString(" 0.123\t", 8), "0.123"); assertEquals(Utils.truncateAndConvertDecimalString("0,123", 8), "0.123"); assertNull(Utils.truncateAndConvertDecimalString(".1", 8)); assertNull(Utils.truncateAndConvertDecimalString(",1", 8)); assertNull(Utils.truncateAndConvertDecimalString("1.", 8)); assertNull(Utils.truncateAndConvertDecimalString("1,", 8)); assertNull(Utils.truncateAndConvertDecimalString("0.0.123", 8)); assertNull(Utils.truncateAndConvertDecimalString("..123", 8)); assertNull(Utils.truncateAndConvertDecimalString("0.0,123", 8)); assertNull(Utils.truncateAndConvertDecimalString("0,0.123", 8)); assertNull(Utils.truncateAndConvertDecimalString("0.X", 8)); assertNull(Utils.truncateAndConvertDecimalString("X.1", 8)); assertNull(Utils.truncateAndConvertDecimalString("-1", 8)); }
public static String truncateAndConvertDecimalString(String number, int maxDecimalPlaces) { if (number == null) { return null; } number = number.trim(); if (!isValidDecimalNumber(number)) { return null; } number = number.replace(',', '.'); boolean foundDot = false; int decimals = 0; char[] chars = number.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c == '.') { if (maxDecimalPlaces == 0) { return number.substring(0, i); } foundDot = true; continue; } if (foundDot) { decimals++; } if (maxDecimalPlaces == decimals) { return number.substring(0, i + 1); } } return number; }
Utils { public static String truncateAndConvertDecimalString(String number, int maxDecimalPlaces) { if (number == null) { return null; } number = number.trim(); if (!isValidDecimalNumber(number)) { return null; } number = number.replace(',', '.'); boolean foundDot = false; int decimals = 0; char[] chars = number.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c == '.') { if (maxDecimalPlaces == 0) { return number.substring(0, i); } foundDot = true; continue; } if (foundDot) { decimals++; } if (maxDecimalPlaces == decimals) { return number.substring(0, i + 1); } } return number; } }
Utils { public static String truncateAndConvertDecimalString(String number, int maxDecimalPlaces) { if (number == null) { return null; } number = number.trim(); if (!isValidDecimalNumber(number)) { return null; } number = number.replace(',', '.'); boolean foundDot = false; int decimals = 0; char[] chars = number.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c == '.') { if (maxDecimalPlaces == 0) { return number.substring(0, i); } foundDot = true; continue; } if (foundDot) { decimals++; } if (maxDecimalPlaces == decimals) { return number.substring(0, i + 1); } } return number; }  }
Utils { public static String truncateAndConvertDecimalString(String number, int maxDecimalPlaces) { if (number == null) { return null; } number = number.trim(); if (!isValidDecimalNumber(number)) { return null; } number = number.replace(',', '.'); boolean foundDot = false; int decimals = 0; char[] chars = number.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c == '.') { if (maxDecimalPlaces == 0) { return number.substring(0, i); } foundDot = true; continue; } if (foundDot) { decimals++; } if (maxDecimalPlaces == decimals) { return number.substring(0, i + 1); } } return number; }  @SuppressLint(Constants.IGNORE_NEW_API) static void setAlpha(View view, float alpha); static String loadEnglish(int resId); static Resources getResourcesByLocale(Context context, String localeName); static Bitmap getMinimalQRCodeBitmap(String url); static boolean isConnected(Context context); static void toastConnectionError(Context context); static void moveView(View view, int startDeltaX, int startDeltaY, int endDeltaX, int endDeltaY, long duration); static void showSimpleMessageDialog(final Context context, int messageResource); static void showSimpleMessageDialog(final Context context, int messageResource, Runnable postRunner); static String formatBlockcountAsApproxDuration(MbwManager mbwManager, final int blocks, final int blockTimeInSeconds); static void showSimpleMessageDialog(final Context context, String message); static void showSimpleMessageDialog(final Context context, String message, final Runnable okayRunner); static void showSimpleMessageDialog(final Context context, String message, final Runnable okayRunner, final Runnable postRunner); static void showSimpleMessageDialog(final Context context, String message, final Runnable okayRunner,
                                              @StringRes int okayButtonText, final Runnable postRunner); static boolean showOptionalMessage(final Context context, int messageResourceId); static boolean showOptionalMessage(final Context context, int messageResourceId, final Runnable onOkay); static String[] stringChopper(String string, int chopLength); static String stringChopper(String string, int chopLength, String joiner); static Double getFiatValue(long satoshis, Double oneBtcInFiat); static String getFiatValueAsString(long satoshis, Double oneBtcInFiat); static void setClipboardString(String string, Context context); static String getClipboardString(Context context); static void clearClipboardString(Activity activity); static Optional<GenericAddress> addressFromString(String someString, NetworkParameters network); static String truncateAndConvertDecimalString(String number, int maxDecimalPlaces); static void pinProtectedWordlistBackup(final Activity activity); static boolean isAppInstalled(Context context, String uri); static void pinProtectedBackup(final Activity activity); static void exportSelectedAccount(final Activity parent); static void preventScreenshots(Activity activity); static boolean checkIsLinked(WalletAccount account, final Collection<? extends WalletAccount> accounts); static boolean isERC20Token(WalletManager walletManager, String symbol); static WalletAccount getLinkedAccount(WalletAccount account, final Collection<? extends WalletAccount> accounts); static EthAccount getLinkedEthAccount(WalletAccount account, final Collection<? extends WalletAccount> accounts); static List<WalletAccount> getLinkedAccounts(WalletAccount account, final Collection<? extends WalletAccount> accounts); static Collection<WalletAccount> getUniqueAccounts(final Collection<WalletAccount> accounts); static List<WalletAccount<?>> sortAccounts(final Collection<WalletAccount<?>> accounts, final MetadataStorage storage); static List<Address> sortAddresses(List<Address> addresses); static List<AddressBookManager.Entry> sortAddressbookEntries(List<AddressBookManager.Entry> entries); static Drawable getDrawableForAccount(WalletAccount walletAccount, boolean isSelectedAccount, Resources resources); static Drawable getDrawableForAccount(AccountViewModel accountView, boolean isSelectedAccount, Resources resources); static String getNameForNewAccount(WalletAccount account, Context context); static boolean isAllowedForLocalTrader(WalletAccount account); static String getFormattedDate(Context context, Date date); static CryptoCurrency getBtcCoinType(); static CryptoCurrency getMtCoinType(); static CryptoCurrency getMassCoinType(); static CryptoCurrency getRmcCoinType(); static boolean isValidEmailAddress(String value); static boolean openWebsite(Context context, String uri); static boolean hasOrRequestCameraAccess(Activity activity); static boolean hasOrRequestLocationAccess(Activity activity); static boolean hasOrRequestAccess(Activity activity, String permission, int requestCode); @Nullable static GenericAssetInfo getTypeByName(String name); }
Utils { public static String truncateAndConvertDecimalString(String number, int maxDecimalPlaces) { if (number == null) { return null; } number = number.trim(); if (!isValidDecimalNumber(number)) { return null; } number = number.replace(',', '.'); boolean foundDot = false; int decimals = 0; char[] chars = number.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c == '.') { if (maxDecimalPlaces == 0) { return number.substring(0, i); } foundDot = true; continue; } if (foundDot) { decimals++; } if (maxDecimalPlaces == decimals) { return number.substring(0, i + 1); } } return number; }  @SuppressLint(Constants.IGNORE_NEW_API) static void setAlpha(View view, float alpha); static String loadEnglish(int resId); static Resources getResourcesByLocale(Context context, String localeName); static Bitmap getMinimalQRCodeBitmap(String url); static boolean isConnected(Context context); static void toastConnectionError(Context context); static void moveView(View view, int startDeltaX, int startDeltaY, int endDeltaX, int endDeltaY, long duration); static void showSimpleMessageDialog(final Context context, int messageResource); static void showSimpleMessageDialog(final Context context, int messageResource, Runnable postRunner); static String formatBlockcountAsApproxDuration(MbwManager mbwManager, final int blocks, final int blockTimeInSeconds); static void showSimpleMessageDialog(final Context context, String message); static void showSimpleMessageDialog(final Context context, String message, final Runnable okayRunner); static void showSimpleMessageDialog(final Context context, String message, final Runnable okayRunner, final Runnable postRunner); static void showSimpleMessageDialog(final Context context, String message, final Runnable okayRunner,
                                              @StringRes int okayButtonText, final Runnable postRunner); static boolean showOptionalMessage(final Context context, int messageResourceId); static boolean showOptionalMessage(final Context context, int messageResourceId, final Runnable onOkay); static String[] stringChopper(String string, int chopLength); static String stringChopper(String string, int chopLength, String joiner); static Double getFiatValue(long satoshis, Double oneBtcInFiat); static String getFiatValueAsString(long satoshis, Double oneBtcInFiat); static void setClipboardString(String string, Context context); static String getClipboardString(Context context); static void clearClipboardString(Activity activity); static Optional<GenericAddress> addressFromString(String someString, NetworkParameters network); static String truncateAndConvertDecimalString(String number, int maxDecimalPlaces); static void pinProtectedWordlistBackup(final Activity activity); static boolean isAppInstalled(Context context, String uri); static void pinProtectedBackup(final Activity activity); static void exportSelectedAccount(final Activity parent); static void preventScreenshots(Activity activity); static boolean checkIsLinked(WalletAccount account, final Collection<? extends WalletAccount> accounts); static boolean isERC20Token(WalletManager walletManager, String symbol); static WalletAccount getLinkedAccount(WalletAccount account, final Collection<? extends WalletAccount> accounts); static EthAccount getLinkedEthAccount(WalletAccount account, final Collection<? extends WalletAccount> accounts); static List<WalletAccount> getLinkedAccounts(WalletAccount account, final Collection<? extends WalletAccount> accounts); static Collection<WalletAccount> getUniqueAccounts(final Collection<WalletAccount> accounts); static List<WalletAccount<?>> sortAccounts(final Collection<WalletAccount<?>> accounts, final MetadataStorage storage); static List<Address> sortAddresses(List<Address> addresses); static List<AddressBookManager.Entry> sortAddressbookEntries(List<AddressBookManager.Entry> entries); static Drawable getDrawableForAccount(WalletAccount walletAccount, boolean isSelectedAccount, Resources resources); static Drawable getDrawableForAccount(AccountViewModel accountView, boolean isSelectedAccount, Resources resources); static String getNameForNewAccount(WalletAccount account, Context context); static boolean isAllowedForLocalTrader(WalletAccount account); static String getFormattedDate(Context context, Date date); static CryptoCurrency getBtcCoinType(); static CryptoCurrency getMtCoinType(); static CryptoCurrency getMassCoinType(); static CryptoCurrency getRmcCoinType(); static boolean isValidEmailAddress(String value); static boolean openWebsite(Context context, String uri); static boolean hasOrRequestCameraAccess(Activity activity); static boolean hasOrRequestLocationAccess(Activity activity); static boolean hasOrRequestAccess(Activity activity, String permission, int requestCode); @Nullable static GenericAssetInfo getTypeByName(String name); static final Function<AddressBookManager.Entry, Comparable> ENTRY_NAME; static final int REQUEST_CAMERA; static final int REQUEST_LOCATION; }