Unfortunately on standard Java SE DecimalFormat doesn't support variable-width groups. So it won't ever format the values exactly as you want to:
If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So
"#,##,###,####" == "######,####" == "##,####,####".
Most number formatting mechanisms in Java are based on that class and therefore inherit this flaw.
ICU4J (the Java version of the International Components for Unicode) provides a NumberFormat class that does support this formatting:
Format format = com.ibm.icu.text.NumberFormat.getCurrencyInstance(new Locale("en", "in"));
System.out.println(format.format(new BigDecimal("100000000")));
This code will produce this output:
Rs 10,00,00,000.00
Note: the com.ibm.icu.text.NumberFormat class does not extend the java.text.NumberFormat class (because it already extends an ICU-internal base class), it does however extend the java.text.Format class, which has the format(Object) method.
Note that the Android version of java.text.DecimalFormat class is implemented using ICU under the hood and does support the feature in the same way that the ICU class itself does (even though the summary incorrectly mentions that it's not supported).
Unfortunately on standard Java SE DecimalFormat doesn't support variable-width groups. So it won't ever format the values exactly as you want to:
If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So
"#,##,###,####" == "######,####" == "##,####,####".
Most number formatting mechanisms in Java are based on that class and therefore inherit this flaw.
ICU4J (the Java version of the International Components for Unicode) provides a NumberFormat class that does support this formatting:
Format format = com.ibm.icu.text.NumberFormat.getCurrencyInstance(new Locale("en", "in"));
System.out.println(format.format(new BigDecimal("100000000")));
This code will produce this output:
Rs 10,00,00,000.00
Note: the com.ibm.icu.text.NumberFormat class does not extend the java.text.NumberFormat class (because it already extends an ICU-internal base class), it does however extend the java.text.Format class, which has the format(Object) method.
Note that the Android version of java.text.DecimalFormat class is implemented using ICU under the hood and does support the feature in the same way that the ICU class itself does (even though the summary incorrectly mentions that it's not supported).
With Android, this worked for me:
new DecimalFormat("##,##,##0").format(amount);
450500 gets formatted as 4,50,500
http://developer.android.com/reference/java/text/DecimalFormat.html - DecimalFormat supports two grouping sizes - the primary grouping size, and one used for all others.
try ICU4J available from Maven central repo
Format format = com.ibm.icu.text.NumberFormat.getNumberInstance(new Locale("en", "IN"));
String str = format.format(100000000);
output
10,00,00,000
if you dont want to you third party libraries you can try this code as well
Format df = new DecimalFormat("###,###,000.00");
int val = 10000000;
System.out.println(df.format(val));
I'd recommend using the java.text package:
double money = 100.1;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(money);
System.out.println(moneyString);
This has the added benefit of being locale specific.
But, if you must, truncate the String you get back if it's a whole dollar:
if (moneyString.endsWith(".00")) {
int centsIndex = moneyString.lastIndexOf(".00");
if (centsIndex != -1) {
moneyString = moneyString.substring(1, centsIndex);
}
}
double amount =200.0;
Locale locale = new Locale("en", "US");
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);
System.out.println(currencyFormatter.format(amount));
or
double amount =200.0;
System.out.println(NumberFormat.getCurrencyInstance(new Locale("en", "US"))
.format(amount));
The best way to display currency
Output
$200.00
Note: Locale constructors have been deprecated. See Obtaining a Locale for other options.

So, since Locale constructors are deprecated, we can use Locale.Builder() to construct a Locale object.
double amount =200.0;
Locale locale = new Locale.Builder().setLanguage("en").setRegion("US").build();
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);
System.out.println(currencyFormatter.format(amount));
or
double amount =200.0;
System.out.println(NumberFormat.getCurrencyInstance(new Locale.Builder().setLanguage("en").setRegion("US").build()).format(amount));
Output
$200.00
If you don't want to use sign use this method
double amount = 200;
DecimalFormat twoPlaces = new DecimalFormat("0.00");
System.out.println(twoPlaces.format(amount));
200.00
This also can be use (With the thousand separator )
double amount = 2000000;
System.out.println(String.format("%,.2f", amount));
2,000,000.00
import com.ibm.icu.text.NumberFormat;
import com.ibm.icu.text.RuleBasedNumberFormat;
public class StringDisplayUtils {
public static String toWords(Double num) {
return ((NumberFormat) (new RuleBasedNumberFormat(String.join("\n",
"Zero;One;Two;Three;Four;Five;Six;Seven;Eight;Nine;Ten;",
"Eleven;Twelve;Thirteen;Fourteen;Fifteen;Sixteen;Seventeen;Eighteen;Nineteen;",
"20: Twenty[ >>];",
"30: Thirty[ >>];",
"40: Forty[ >>];",
"50: Fifty[ >>];",
"60: Sixty[ >>];",
"70: Seventy[ >>];",
"80: Eighty[ >>];",
"90: Ninety[ >>];",
"1,00: << Hundred[ >>];",
"1,000: << Thousand[ >>];",
"1,000,00: << Lakh[ >>];",
"1,000,00,00: << Crore[ >>];",
"1,000,00,00,000,00,00,00: OUT OF RANGE!;"
)))).format(num);
}
}
this might help!
I dont think you will get that. As per the javadoc, this is the nomenclature they have... beyond thousand
1,000,000: << million[ >>];
1,000,000,000: << billion[ >>];
1,000,000,000,000: << trillion[ >>];
1,000,000,000,000,000: OUT OF RANGE!;
IMHO, you need to write custom logic. For e.g replace all "hundrend thousand" with lakh
According to the JDK release notes, you have locale codes hi_IN (Hindi) and en_IN (English).
System.out.println(Currency.getInstance(new Locale("hi", "IN")).getSymbol());
heres is simple thing u can do ,
float amount = 100000;
NumberFormat formatter = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
String moneyString = formatter.format(amount);
System.out.println(moneyString);
The output will be , Rs.100,000.00 .
You can do this by using locale like
Here you can use any locale for your case it should be en_IN
NumberFormat.getCurrencyInstance(locale).format(paramDouble);
You could use the java.text.DecimalFormat
and do something like this:
DecimalFormat df = new DecimalFormat(###,##0);
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
dfs.setDecimalSeparator('.');
dfs.setGroupingSeparator(',');
df.setDecimalFormatSymbols(dfs);
df.format(numberToFormat);