Java BigInteger Calculate parseBigInteger(String s, BigInteger defaultValue)

Here you can find the source of parseBigInteger(String s, BigInteger defaultValue)

Description

parse Big Integer

License

Apache License

Declaration

public static BigInteger parseBigInteger(String s, BigInteger defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.math.BigInteger;

public class Main {
    public static BigInteger parseBigInteger(String s, BigInteger defaultValue) {
        String ch = getNumberChars(s);
        if (ch == null) {
            return defaultValue;
        }//from  ww w.j a  v a  2 s .c  om
        return new BigInteger(ch);
    }

    public static String getNumberChars(String s) {
        if (s == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if ('0' <= c && c <= '9') {
                if (i == 1 && s.charAt(0) == '-') {
                    sb.append('-');
                }
                sb.append(c);
            }
        }
        if (sb.length() == 0) {
            return null;
        } else {
            return sb.toString();
        }
    }
}

Related

  1. negative(BigInteger n)
  2. normalizarParaBigInteger(Number numero, RoundingMode modo)
  3. numberToIpv4(BigInteger ipNumber)
  4. numberToShortString(BigInteger number)
  5. order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[])
  6. parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative)
  7. parseScaledNonNegativeBigInteger(String str)
  8. product(final BigInteger min, final BigInteger max)
  9. randomFromZn(BigInteger n, Random rand)