Java Code Examples for java.text.DecimalFormat#setGroupingSize()
The following examples show how to use
java.text.DecimalFormat#setGroupingSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDecimalFormat.java From util4j with Apache License 2.0 | 6 votes |
public static void test2(DecimalFormat df) { int number = 155566; //默认整数部分三个一组, System.out.println(number);//输出格式155,566 //设置每四个一组 df.setGroupingSize(4); System.out.println(df.format(number));//输出格式为15,5566 DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(); //设置小数点分隔符 dfs.setDecimalSeparator(';'); //设置分组分隔符 dfs.setGroupingSeparator('a'); df.setDecimalFormatSymbols(dfs); System.out.println(df.format(number));//15a5566 System.out.println(df.format(11.22));//11;22 //取消分组 df.setGroupingUsed(false); System.out.println(df.format(number)); }
Example 2
Source File: CommonUtils.java From HHComicViewer with Apache License 2.0 | 6 votes |
private static String[] fileSize(long size) { String s = ""; if (size > 1024) { s = "KB"; size /= 1024; if (size > 1024) { s = "MB"; size /= 1024; } } DecimalFormat df = new DecimalFormat(); df.setGroupingSize(3); String[] result = new String[3]; result[0] = df.format(size); result[1] = s; return result; }
Example 3
Source File: AbstractGraphicsDocument.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * Initialise the abstract graphics document, specifically meant to set the formatter. * * @param defaultMaxDigits default max digits */ public AbstractGraphicsDocument(int defaultMaxDigits) { Locale locale = new Locale("en", "US"); DecimalFormatSymbols decimalSymbols = new DecimalFormatSymbols(locale); decimalSymbols.setDecimalSeparator('.'); formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols(decimalSymbols); // do not group formatter.setGroupingSize(0); // do not show decimal SEPARATOR if it is not needed formatter.setDecimalSeparatorAlwaysShown(false); formatter.setGroupingUsed(false); // set default number of fraction digits formatter.setMaximumFractionDigits(defaultMaxDigits); // minimum fraction digits to 0 so they get not rendered if not needed formatter.setMinimumFractionDigits(0); }
Example 4
Source File: Currency.java From SaneEconomy with GNU General Public License v3.0 | 5 votes |
public static Currency fromConfig(ConfigurationSection config) { DecimalFormat format = new DecimalFormat(config.getString("format", "0.00")); if (config.getInt("grouping", 0) > 0) { DecimalFormatSymbols symbols = format.getDecimalFormatSymbols(); if (symbols.getDecimalSeparator() == ',') { // French symbols.setGroupingSeparator(' '); } else { symbols.setGroupingSeparator(','); } String groupingSeparator = config.getString("grouping-separator", null); if (!Strings.isNullOrEmpty(groupingSeparator)) { symbols.setGroupingSeparator(groupingSeparator.charAt(0)); } String decimalSeparator = config.getString("decimal-separator", "."); if (!Strings.isNullOrEmpty(decimalSeparator)) { symbols.setDecimalSeparator(decimalSeparator.charAt(0)); } format.setDecimalFormatSymbols(symbols); format.setGroupingUsed(true); format.setGroupingSize(3); } return new Currency( config.getString("name.singular", "dollar"), config.getString("name.plural", "dollars"), format, config.getString("balance-format", "{1} {2}") ); }
Example 5
Source File: AdministrativeStaff.java From KEEL with GNU General Public License v3.0 | 5 votes |
protected DecimalFormat format() { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(3); df.setMinimumFractionDigits(3); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setDecimalSeparator((new String(".").charAt(0))); df.setDecimalFormatSymbols(dfs); df.setGroupingSize(20); return df; }
Example 6
Source File: numberFormat.java From openbd-core with GNU General Public License v3.0 | 5 votes |
protected cfData defaultExecute( cfSession _session, List<cfData> parameters, DecimalFormatSymbols _dfs )throws cfmRunTimeException{ double val = getFormatValue( _session, parameters.get(0) ); DecimalFormat DF = new DecimalFormat("#,###", _dfs); DF.setGroupingSize( 3 ); return new cfStringData( DF.format( val ) ); }
Example 7
Source File: DecimalFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_setGroupingSize() { DecimalFormat df = new DecimalFormat("###0.##", new DecimalFormatSymbols(Locale.ENGLISH)); df.setGroupingUsed(true); df.setGroupingSize(2); assertEquals("Value not set", 2, df.getGroupingSize()); String result = df.format(123); assertTrue("Invalid format:" + result, result.equals("1,23")); }
Example 8
Source File: MathUtils.java From latexdraw with GNU General Public License v3.0 | 5 votes |
private MathUtils() { super(); format = (DecimalFormat) DecimalFormat.getNumberInstance(Locale.ENGLISH); format.setMaximumFractionDigits(3); format.setRoundingMode(RoundingMode.HALF_EVEN); format.getDecimalFormatSymbols().setDecimalSeparator('.'); format.setDecimalSeparatorAlwaysShown(false); format.setGroupingSize(0); doubleRegex = "[-]?[0-9]*\\.?[0-9]+"; }