Here you can find the source of formatNumberWithKSeparators(int value)
Parameter | Description |
---|---|
value | a parameter |
public static String formatNumberWithKSeparators(int value)
//package com.java2s; //License from project: LGPL public class Main { /**//from w w w .jav a2 s . c om * Formats the number in value with thousand separator "," for display. * @param value * @return */ public static String formatNumberWithKSeparators(int value) { StringBuilder sb = new StringBuilder(16); String number = String.valueOf(value); int len = number.length(); int end = len % 3, i = 0; sb.append(number.substring(0, end)); for (i = end; i <= (len - 3); i += 3) { if (i > 0) { sb.append(","); } sb.append(number.substring(i, i + 3)); } return sb.toString(); } }