title: Replace numbers with string representation
body: <p>I am trying to make a program, that displays rather large numbers (BigInteger large). To make it easier for the user, I am displaying the numbers as string (1 000 000 = 1 Million). My below code shows my current attempt. My problem lies, in the fact that the actual number that I am replacing will not be nice and round. This program does not need to <strong>display</strong> the 100% accurate value, rather give a ball park figure. I.E:</p>
  
  <pre><code>1 234 567 = 1 Million
  1 000 000 = 1 Million
  1 934 234 = 1 Million
  </code></pre>
  
  <p>My current code (Shortened for brevity):</p>
  
  <pre><code>            if (!displayNumbers) {
                  StringBuffer sb = new StringBuffer(_combinations);
                  String t = sb.reverse().toString();
  
                  Toast.makeText(getApplicationContext(), t, 1).show();
  
                  ...
  
                  if (t.contains("000 000 000 000 000")) {
                      t.replace("000 000 000 000 000", "quadrillion");
                  }
  
                  if (t.contains("000 000 000 000")) {
                      t.replace("000 000 000 000", "trillion");
                  }
  
                  if (t.contains("000 000 000")) {
                      t.replace("000 000 000", "billion");
                  }
  
                  if (t.contains("000 000")) {
                      t.replace("000 000", "million");
                  }
  
                  sb = new StringBuffer(t);
                  _combinations = sb.reverse().toString();
              }
  </code></pre>
  
  <p>I was thinking something along the lines of replacing the zero's with <code>#'s</code> so that it would just search for <code>x lots of 3 digits</code> and replace with corresponding word, but I do not know how to implement this. I should also note that I am aware that the <code>million, billion, etc</code> are currently spelt backwards in the final output string.</p>
  
  <p>EDIT: Should note for UK readers that I am using USA definitions of <code>*illions</code>.</p>
  
  <p>EDIT 2: Been doing some more Googling and found this - <a href="https://stackoverflow.com/questions/7737946/java-regex-replace-all-numerical-values-with-one-number">java Regex: replace all numerical values with one number</a>. Except I have no idea how to modify the Regex for finding <code>000 000</code>.</p>