title: How to go about formatting 1200 to 1.2k in java
body: <p>I'd like to format following numbers into the numbers next to them with java:</p>
  
  <pre><code>1000 to 1k
  5821 to 5.8k
  10500 to 10k
  101800 to 101k
  2000000 to 2m
  7800000 to 7.8m
  92150000 to 92m
  123200000 to 123m
  </code></pre>
  
  <p>The number on the right will be long or integer the number on the left will be string.
  How should I approach this. I already did little algorithm for this but I thought there might be already something invented out there that does nicer job at it and doesn't require additional testing if I start dealing with billions and trillions :)</p>
  
  <p>Additional Requirements:</p>
  
  <ul>
  <li>The format should have maximum of 4 characters   </li>
  <li>The above means 1.1k is OK 11.2k is not. Same for 7.8m is OK 19.1m is not. Only one digit before decimal point is allowed to have decimal point. Two digits before decimal point means not digits after decimal point.  </li>
  <li>No rounding is necessary.  (Numbers being displayed with k and m appended are more of analog gauge indicating approximation not precise article of logic. Hence rounding is irrelevant mainly due to nature of variable than can increase or decrees several digits even while you are looking at the cached result.)</li>
  </ul>