Partially resolved #78 (#96)

* Partially resolved #78 (Hacktoberfest initiative)

* Removing trailing whitespaces
This commit is contained in:
vic-nik
2017-10-22 13:09:20 +05:30
committed by Shekhar Gulati
parent befff2625b
commit da85915b8d
2 changed files with 31 additions and 0 deletions
+23
View File
@@ -1389,6 +1389,29 @@ public abstract class Strman {
return resultBuilder.toString();
}
/**
* Returns a string representation of the number passed in where groups of three digits are delimited by comma
*
* @param number Input number
* @return formatted String
*/
public static String formatNumber(long number) {
String stringRepresentation = Long.toString(number);
StringBuilder sb = new StringBuilder();
int bound = stringRepresentation.length() - 1;
String delimiter = ",";
int counter = 0;
for (int i = bound; i >= 0; i--) {
char c = stringRepresentation.charAt(i);
if (i != bound && counter % 3 == 0) {
sb.append(delimiter);
}
sb.append(c);
counter++;
}
return sb.reverse().toString();
}
public static String[] chop(String input, int step) {
if (input == null || input.length() == 0) {
return EMPTY_ARRAY;