Java Code Examples for java.text.DecimalFormat#getDecimalFormatSymbols()
The following examples show how to use
java.text.DecimalFormat#getDecimalFormatSymbols() .
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: TestShrinkAuxiliaryData.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private void printTestInfo(int maxCacheSize) { DecimalFormat grouped = new DecimalFormat("000,000"); DecimalFormatSymbols formatSymbols = grouped.getDecimalFormatSymbols(); formatSymbols.setGroupingSeparator(' '); grouped.setDecimalFormatSymbols(formatSymbols); System.out.format( "Test will use %s bytes of memory of %s available%n" + "Available memory is %s with %d bytes pointer size - can save %s pointers%n" + "Max cache size: 2^%d = %s elements%n", grouped.format(ShrinkAuxiliaryDataTest.getMemoryUsedByTest()), grouped.format(Runtime.getRuntime().maxMemory()), grouped.format(Runtime.getRuntime().maxMemory() - ShrinkAuxiliaryDataTest.getMemoryUsedByTest()), Unsafe.ADDRESS_SIZE, grouped.format((Runtime.getRuntime().freeMemory() - ShrinkAuxiliaryDataTest.getMemoryUsedByTest()) / Unsafe.ADDRESS_SIZE), maxCacheSize, grouped.format((int) Math.pow(2, maxCacheSize)) ); }
Example 2
Source File: TestShrinkAuxiliaryData.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private void printTestInfo(int maxCacheSize) { DecimalFormat grouped = new DecimalFormat("000,000"); DecimalFormatSymbols formatSymbols = grouped.getDecimalFormatSymbols(); formatSymbols.setGroupingSeparator(' '); grouped.setDecimalFormatSymbols(formatSymbols); System.out.format( "Test will use %s bytes of memory of %s available%n" + "Available memory is %s with %d bytes pointer size - can save %s pointers%n" + "Max cache size: 2^%d = %s elements%n", grouped.format(ShrinkAuxiliaryDataTest.getMemoryUsedByTest()), grouped.format(Runtime.getRuntime().maxMemory()), grouped.format(Runtime.getRuntime().maxMemory() - ShrinkAuxiliaryDataTest.getMemoryUsedByTest()), Unsafe.ADDRESS_SIZE, grouped.format((Runtime.getRuntime().freeMemory() - ShrinkAuxiliaryDataTest.getMemoryUsedByTest()) / Unsafe.ADDRESS_SIZE), maxCacheSize, grouped.format((int) Math.pow(2, maxCacheSize)) ); }
Example 3
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 4
Source File: ExcelUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
private static void updateExcelDecimalSeparator( DecimalFormat numberFormat ) { DecimalFormatSymbols symbol = numberFormat.getDecimalFormatSymbols( ); if ( symbol.getDecimalSeparator( ) != EXCEL_DECIMAL_SEPARATOR ) { symbol.setDecimalSeparator( EXCEL_DECIMAL_SEPARATOR ); numberFormat.setDecimalFormatSymbols( symbol ); } }
Example 5
Source File: BtcFormat.java From green_android with GNU General Public License v3.0 | 5 votes |
/** Set the currency symbol and international code of the underlying {@link * java.text.NumberFormat} object to the values of the last two arguments, respectively. * This method is invoked in the process of parsing, not formatting. * * Only invoke this from code synchronized on value of the first argument, and don't * forget to put the symbols back otherwise equals(), hashCode() and immutability will * break. */ private static DecimalFormatSymbols setSymbolAndCode(DecimalFormat numberFormat, String symbol, String code) { checkState(Thread.holdsLock(numberFormat)); DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols(); DecimalFormatSymbols ante = (DecimalFormatSymbols)fs.clone(); fs.setInternationalCurrencySymbol(code); fs.setCurrencySymbol(symbol); numberFormat.setDecimalFormatSymbols(fs); return ante; }
Example 6
Source File: UI.java From green_android with GNU General Public License v3.0 | 5 votes |
public static void localeDecimalInput(final EditText editText) { final DecimalFormat decFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault()); final DecimalFormatSymbols symbols=decFormat.getDecimalFormatSymbols(); final String defaultSeparator = Character.toString(symbols.getDecimalSeparator()); final String otherSeparator = ".".equals(defaultSeparator) ? "," : "."; editText.setHint(String.format("0%s00",defaultSeparator)); editText.addTextChangedListener(new TextWatcher() { private boolean isEditing =false; @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { Log.d(TAG,s + " " + start + " " + before + " " + count); } @Override public void afterTextChanged(Editable editable) { if (isEditing) return; isEditing = true; final int index = editable.toString().indexOf(otherSeparator); if (index > 0) editable.replace(index,index+1, defaultSeparator); if (editable.toString().contains(".") || editable.toString().contains(",")) editText.setKeyListener(DigitsKeyListener.getInstance("0123456789")); else editText.setKeyListener(DigitsKeyListener.getInstance("0123456789.,")); isEditing =false; } }); }
Example 7
Source File: DecimalFormatUtil.java From RxAndroidBootstrap with Apache License 2.0 | 5 votes |
/** * Returns a thousans separated decimar formatter. * * @return */ public static DecimalFormat getThousandSeperatedDecimalFormat() { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.US); DecimalFormatSymbols symbols = df.getDecimalFormatSymbols(); symbols.setGroupingSeparator(' '); df.setDecimalFormatSymbols(symbols); return df; }
Example 8
Source File: MarvinMatrixPanel.java From marvinproject with GNU Lesser General Public License v3.0 | 5 votes |
public MarvinMatrixPanel(int rows, int columns){ this.rows = rows; this.columns = columns; JPanel panelTextFields = new JPanel(); GridLayout layout = new GridLayout(rows, columns); panelTextFields.setLayout(layout); //Format DecimalFormat decimalFormat = new DecimalFormat(); DecimalFormatSymbols dfs = decimalFormat.getDecimalFormatSymbols(); dfs.setDecimalSeparator('.'); decimalFormat.setDecimalFormatSymbols(dfs); textFields = new JFormattedTextField[rows][columns]; for(int r=0; r<rows; r++){ for(int c=0; c<columns; c++){ textFields[r][c] = new JFormattedTextField(decimalFormat); textFields[r][c].setValue(0.0); textFields[r][c].setColumns(4); panelTextFields.add(textFields[r][c]); } } setLayout(new FlowLayout(FlowLayout.CENTER)); add(panelTextFields); }
Example 9
Source File: GeneralUtilities.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
public static char getGroupingSeparator(Locale locale) { DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(locale); DecimalFormatSymbols decimalFormatSymbols = df.getDecimalFormatSymbols(); logger.debug("IN"); char thousands = decimalFormatSymbols.getGroupingSeparator(); logger.debug("OUT"); return thousands; }
Example 10
Source File: Helpers.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * @return a number formatter instance which prints numbers in a human * readable form, like 9_223_372_036_854_775_807. */ public static NumberFormat numberFormatter() { DecimalFormat df = new DecimalFormat(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setGroupingSeparator('_'); dfs.setDecimalSeparator('.'); df.setDecimalFormatSymbols(dfs); return df; }
Example 11
Source File: TestgetPatternSeparator_ja.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] argv) throws Exception { DecimalFormat df = (DecimalFormat)NumberFormat.getInstance(Locale.JAPAN); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); if (dfs.getPatternSeparator() != ';') { throw new Exception("DecimalFormatSymbols.getPatternSeparator doesn't return ';' in ja locale"); } }
Example 12
Source File: TestgetPatternSeparator_ja.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] argv) throws Exception { DecimalFormat df = (DecimalFormat)NumberFormat.getInstance(Locale.JAPAN); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); if (dfs.getPatternSeparator() != ';') { throw new Exception("DecimalFormatSymbols.getPatternSeparator doesn't return ';' in ja locale"); } }
Example 13
Source File: CatmullRomSpline.java From PyramidShader with GNU General Public License v3.0 | 5 votes |
@Override public String toString() { DecimalFormat formatter = new DecimalFormat("##0.####"); DecimalFormatSymbols dfs = formatter.getDecimalFormatSymbols(); dfs.setDecimalSeparator('.'); formatter.setDecimalFormatSymbols(dfs); StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.x.length; i++) { sb.append(formatter.format(x[i])); sb.append(" "); sb.append(formatter.format(y[i])); sb.append(" "); } return sb.toString(); }
Example 14
Source File: UserSessionLocale.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 5 votes |
private UserSessionLocale(final String adLanguage) { final Language language = Language.getLanguage(adLanguage); if (language == null) { throw new IllegalArgumentException("No language found for " + adLanguage); } this.adLanguage = language.getAD_Language(); final DecimalFormat decimalFormat = DisplayType.getNumberFormat(DisplayType.Amount, language); final DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols(); numberDecimalSeparator = decimalFormatSymbols.getDecimalSeparator(); numberGroupingSeparator = decimalFormatSymbols.getGroupingSeparator(); }
Example 15
Source File: BtcFormat.java From GreenBits with GNU General Public License v3.0 | 5 votes |
/** Set the currency symbol and international code of the underlying {@link * java.text.NumberFormat} object to the values of the last two arguments, respectively. * This method is invoked in the process of parsing, not formatting. * * Only invoke this from code synchronized on value of the first argument, and don't * forget to put the symbols back otherwise equals(), hashCode() and immutability will * break. */ private static DecimalFormatSymbols setSymbolAndCode(DecimalFormat numberFormat, String symbol, String code) { checkState(Thread.holdsLock(numberFormat)); DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols(); DecimalFormatSymbols ante = (DecimalFormatSymbols)fs.clone(); fs.setInternationalCurrencySymbol(code); fs.setCurrencySymbol(symbol); numberFormat.setDecimalFormatSymbols(fs); return ante; }
Example 16
Source File: DecimalFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_exponentSeparator() throws Exception { DecimalFormat df = new DecimalFormat("0E0"); assertEquals("1E4", df.format(12345.)); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setExponentSeparator("-useless-api-"); df.setDecimalFormatSymbols(dfs); assertEquals("1-useless-api-4", df.format(12345.)); }
Example 17
Source File: MCRDecimalConverter.java From mycore with GNU General Public License v3.0 | 4 votes |
private boolean hasMultipleDecimalSeparators(String string, DecimalFormat df) { DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); String patternNonDecimalSeparators = "[^" + dfs.getDecimalSeparator() + "]"; String decimalSeparatorsLeftOver = string.replaceAll(patternNonDecimalSeparators, ""); return (decimalSeparatorsLeftOver.length() > 1); }
Example 18
Source File: StackTreeTest.java From mjprof with GNU Lesser General Public License v3.0 | 4 votes |
private static char getSeparator() { DecimalFormat format= (DecimalFormat) DecimalFormat.getInstance(); DecimalFormatSymbols symbols=format.getDecimalFormatSymbols(); char sep=symbols.getDecimalSeparator(); return sep; }
Example 19
Source File: BtcFormat.java From bcm-android with GNU General Public License v3.0 | 3 votes |
/** * Set both the currency symbol and code of the underlying, mutable NumberFormat object * according to the given denominational units scale factor. This is for formatting, not parsing. * <p> * <p>Set back to zero when you're done formatting otherwise immutability, equals() and * hashCode() will break! * * @param scale Number of places the decimal point will be shifted when formatting * a quantity of satoshis. */ protected static void prefixUnitsIndicator(DecimalFormat numberFormat, int scale) { checkState(Thread.holdsLock(numberFormat)); // make sure caller intends to reset before changing DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols(); setSymbolAndCode(numberFormat, prefixSymbol(fs.getCurrencySymbol(), scale), prefixCode(fs.getInternationalCurrencySymbol(), scale) ); }
Example 20
Source File: NumberExpression.java From MeteoInfo with GNU Lesser General Public License v3.0 | 2 votes |
/** * Determines whether the specified char is a number * * @param c The char * @return If the char is a digit or a decimal separator */ public static boolean isNumber(char c) { DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(); DecimalFormatSymbols symbols = format.getDecimalFormatSymbols(); return Character.isDigit(c) || symbols.getDecimalSeparator() == c; }