@Test public void testParseBigDecimal() throws Exception { setConfigurationLocale(Locale.UK); assertThat(Numbers.parseBigDecimal("1").get().toPlainString()).isEqualTo("1"); assertThat(Numbers.parseBigDecimal("-1").get().toPlainString()).isEqualTo("-1"); assertThat(Numbers.parseBigDecimal("01").get().toPlainString()).isEqualTo("1"); assertThat(Numbers.parseBigDecimal("-01").get().toPlainString()).isEqualTo("-1"); assertThat(Numbers.parseBigDecimal("1.0").get().toPlainString()).isEqualTo("1"); assertThat(Numbers.parseBigDecimal("1,000.01").get().toPlainString()).isEqualTo("1000.01"); assertThat(Numbers.parseBigDecimal("1,00001").get().toPlainString()).isEqualTo("100001"); assertThat(Numbers.parseBigDecimal("1,0,0,0,0,1").get().toPlainString()).isEqualTo("100001"); assertThat(Numbers.parseBigDecimal("1,0,0,0,0,1").get().toPlainString()).isEqualTo("100001"); setConfigurationLocale(new Locale("ru")); assertThat(Numbers.parseBigDecimal("1").get().toPlainString()).isEqualTo("1"); assertThat(Numbers.parseBigDecimal("-1").get().toPlainString()).isEqualTo("-1"); assertThat(Numbers.parseBigDecimal("01").get().toPlainString()).isEqualTo("1"); assertThat(Numbers.parseBigDecimal("-01").get().toPlainString()).isEqualTo("-1"); assertThat(Numbers.parseBigDecimal("1,0").get().toPlainString()).isEqualTo("1"); assertThat(Numbers.parseBigDecimal("1 000,01").get().toPlainString()).isEqualTo("1000.01"); assertThat(Numbers.parseBigDecimal("1 00001").get().toPlainString()).isEqualTo("100001"); assertThat(Numbers.parseBigDecimal("1 0 0 0 0 1").get().toPlainString()).isEqualTo("100001"); }
public static Optional<BigDecimal> parseBigDecimal(String text) { if (!Strings.isNullOrEmpty(text)) { text = text.replace(" ", "\u00a0"); DecimalFormat format = newDecimalFormat("#,##0.000000000000000", 8); ParsePosition pos = new ParsePosition(0); Number value = format.parse(text, pos); if (text.length() != pos.getIndex()) { return Optional.absent(); } return Optional.of(new BigDecimal(value.toString())); } else { return Optional.absent(); } }
Numbers { public static Optional<BigDecimal> parseBigDecimal(String text) { if (!Strings.isNullOrEmpty(text)) { text = text.replace(" ", "\u00a0"); DecimalFormat format = newDecimalFormat("#,##0.000000000000000", 8); ParsePosition pos = new ParsePosition(0); Number value = format.parse(text, pos); if (text.length() != pos.getIndex()) { return Optional.absent(); } return Optional.of(new BigDecimal(value.toString())); } else { return Optional.absent(); } } }
Numbers { public static Optional<BigDecimal> parseBigDecimal(String text) { if (!Strings.isNullOrEmpty(text)) { text = text.replace(" ", "\u00a0"); DecimalFormat format = newDecimalFormat("#,##0.000000000000000", 8); ParsePosition pos = new ParsePosition(0); Number value = format.parse(text, pos); if (text.length() != pos.getIndex()) { return Optional.absent(); } return Optional.of(new BigDecimal(value.toString())); } else { return Optional.absent(); } } private  Numbers(); }
Numbers { public static Optional<BigDecimal> parseBigDecimal(String text) { if (!Strings.isNullOrEmpty(text)) { text = text.replace(" ", "\u00a0"); DecimalFormat format = newDecimalFormat("#,##0.000000000000000", 8); ParsePosition pos = new ParsePosition(0); Number value = format.parse(text, pos); if (text.length() != pos.getIndex()) { return Optional.absent(); } return Optional.of(new BigDecimal(value.toString())); } else { return Optional.absent(); } } private  Numbers(); static boolean isNumeric(String text); static boolean isNumeric(String text, Locale locale); static Optional<BigDecimal> parseBigDecimal(String text); static NumberFormatter newEditFormatter(int decimalPlaces, int maxLength); static NumberFormatter newDisplayFormatter(int decimalPlaces, int maxLength); }
Numbers { public static Optional<BigDecimal> parseBigDecimal(String text) { if (!Strings.isNullOrEmpty(text)) { text = text.replace(" ", "\u00a0"); DecimalFormat format = newDecimalFormat("#,##0.000000000000000", 8); ParsePosition pos = new ParsePosition(0); Number value = format.parse(text, pos); if (text.length() != pos.getIndex()) { return Optional.absent(); } return Optional.of(new BigDecimal(value.toString())); } else { return Optional.absent(); } } private  Numbers(); static boolean isNumeric(String text); static boolean isNumeric(String text, Locale locale); static Optional<BigDecimal> parseBigDecimal(String text); static NumberFormatter newEditFormatter(int decimalPlaces, int maxLength); static NumberFormatter newDisplayFormatter(int decimalPlaces, int maxLength);  }