Example usage for java.text DecimalFormatSymbols DecimalFormatSymbols

List of usage examples for java.text DecimalFormatSymbols DecimalFormatSymbols

Introduction

In this page you can find the example usage for java.text DecimalFormatSymbols DecimalFormatSymbols.

Prototype

public DecimalFormatSymbols(Locale locale) 

Source Link

Document

Create a DecimalFormatSymbols object for the given locale.

Usage

From source file:com.mendhak.gpslogger.common.OpenGTSClient.java

public static String NMEAGPRMCCoord(double coord) {
    // DDDMM.MMMMM?
    int degrees = (int) coord;
    double minutes = (coord - degrees) * 60;

    DecimalFormat df = new DecimalFormat("00.00000", new DecimalFormatSymbols(Locale.US));
    StringBuilder rCoord = new StringBuilder();
    rCoord.append(degrees);/*from w  w w  .  j  av  a2 s.  c o m*/
    rCoord.append(df.format(minutes));

    return rCoord.toString();
}

From source file:org.mitre.ccv.mapred.CompleteCompositionVectorUtils.java

/**
 * Writes out the {@link SequenceFile} feature vectors in row major (packed) order. No labels are outputed.
 *
 * @param jobConf//w  w  w.  j  av a2  s.c o  m
 * @param input     top level SequenceFile directory path
 * @param output    path to output the matrix
 * @param digits    the maximum number of fraction digits
 * @throws IOException
 */
public static void featureVectors2RowMajorMatrix(JobConf jobConf, String input, String output, int digits)
        throws IOException {
    JobConf conf = new JobConf(jobConf, CalculateCosineDistanceMatrix.class);

    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);
    format.setMaximumFractionDigits(digits);
    //format.setMinimumFractionDigits(fractionDigits);
    format.setGroupingUsed(false);

    final Path inputPath = new Path(input);
    final FileSystem fs = inputPath.getFileSystem(conf);
    final Path qInputPath = fs.makeQualified(inputPath);
    final Path outputPath = new Path(output);
    Path[] paths = FileUtils.ls(conf, qInputPath.toString() + Path.SEPARATOR + "part-*");

    FSDataOutputStream fos = fs.create(outputPath, true); // throws nothing!
    final Writer writer = new OutputStreamWriter(fos);
    final Text key = new Text();
    final SparseVectorWritable value = new SparseVectorWritable();
    for (int idx = 0; idx < paths.length; idx++) {
        SequenceFile.Reader reader = new SequenceFile.Reader(fs, paths[idx], conf);
        boolean hasNext = reader.next(key, value);
        while (hasNext) {

            final SparseVector vector = value.get();
            final StringBuilder sb = new StringBuilder();
            for (int i = 0; i < vector.getCardinality(); i++) {
                final String s = format.format(vector.get(i)); // format the number
                sb.append(s);
                sb.append(' ');
            }
            writer.write(sb.toString());
            hasNext = reader.next(key, value);
        }
        try {
            writer.flush();
            reader.close();
        } catch (IOException ioe) {
            // closing the SequenceFile.Reader will throw an exception if the file is over some unknown size
            LOG.debug("Probably caused by closing the SequenceFile.Reader. All is well", ioe);
        }
    }
    try {
        writer.close();
        fos.flush();
        fos.close();
    } catch (IOException ioe) {
        LOG.debug("Caused by distributed cache output stream.", ioe);
    }
}

From source file:org.sakaiproject.tool.gradebook.ui.GradebookDependentBean.java

/**
 * Gets a localized percent input symbol based on the locale determined by FacesContext.
 *///from   w  w w  .  java  2 s.c  o  m
public String getLocalizedPercentInput() {
    Locale locale = LocaleUtil.getLocale(FacesContext.getCurrentInstance());
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
    return String.valueOf(dfs.getPercent());
}

From source file:bigtweet.model.StudyingBeacons.java

/**
 * Extra ouput file to generate a chart 
 * call plotBeaconStudy in R project to obtain chart
 *///  w w  w .j av  a2s. c o m
private void generateBatchOuputForChart(JSONArray parametersValues, int parametersValuesIndex,
        double meanEndorsers) {

    JSONObject parameters = (JSONObject) parametersValues.get(parametersValuesIndex);//parameters
    JSONObject aux = new JSONObject();
    aux.put("links", parameters.get("beaconLinksNumber"));
    aux.put("centrality", parameters.get("beaconLinksCentrality"));
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    DecimalFormat df = new DecimalFormat("0.000", otherSymbols);
    aux.put("meanEndorsers", df.format(meanEndorsers));
    JSONForChart.add(aux);

    //write json file
    FileWriter file;
    try {
        file = new FileWriter(batchOutputFileForChart);
        file.write(JSONForChart.toJSONString());
        file.flush();
        file.close();
    } catch (Exception ex) {
        Logger.getLogger(BTSimBatch.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java

public static String formatNumberWithOriginalNumberOfDecimals(String stringToFormat) {

    if (stringToFormat == null || stringToFormat.length() == 0) {
        return null;
    }//from www .ja  v  a2  s. c  om

    String result = null;

    DecimalFormat formatter = new DecimalFormat("#################.####################",
            new DecimalFormatSymbols(getDefaultFormattingLocale()));

    try {
        result = formatter.format(Double.parseDouble(stringToFormat));
    } catch (Exception e) {
        LOG.warn("Could not format string " + stringToFormat
                + " as number with original number of decimals (StringUtilities)", e);

        return null;
    }

    return result;
}

From source file:com.netease.qa.emmagee.service.EmmageeService.java

@Override
public void onCreate() {
    Log.i(LOG_TAG, "service onCreate");
    super.onCreate();
    isServiceStop = false;/*from w  ww . j av a  2 s  . c  o m*/
    isStop = false;
    fpsInfo = new FpsInfo();
    memoryInfo = new MemoryInfo();
    procInfo = new ProcessInfo();
    fomart = new DecimalFormat();
    fomart.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    fomart.setGroupingUsed(false);
    fomart.setMaximumFractionDigits(2);
    fomart.setMinimumFractionDigits(0);
    des = new EncryptData("emmagee");
    currentInfo = new CurrentInfo();
    statusBarHeight = getStatusBarHeight();
    batteryBroadcast = new BatteryInfoBroadcastReceiver();
    registerReceiver(batteryBroadcast, new IntentFilter(BATTERY_CHANGED));
}

From source file:org.osaf.cosmo.eim.eimml.EimmlTypeConverter.java

/**
 * Returns the given value as a string.//from  ww  w . j  a v  a 2  s.  co m
 *
 * @throws IllegalArgumentException if digits or decimal places
 * is not positive
 */
public static String fromDecimal(BigDecimal value, int digits, int decimalPlaces)
        throws EimmlConversionException {
    if (value == null)
        return null;

    if (digits <= 0)
        throw new IllegalArgumentException("Number of digits must be positive");
    if (decimalPlaces < 0)
        throw new IllegalArgumentException("Number of decimal places must be positive or 0");

    StringBuffer pattern = new StringBuffer();
    for (int i = 1; i <= digits; i++)
        pattern.append("#");
    if (decimalPlaces > 0) {
        pattern.append(".");
        for (int i = 1; i <= decimalPlaces; i++)
            pattern.append("#");
    }

    // make sure to always format with same symbols (US locale)
    return new DecimalFormat(pattern.toString(), new DecimalFormatSymbols(Locale.US)).format(value);
}

From source file:fr.cs.examples.propagation.TrackCorridor.java

private void run(final File input, final File output, final String separator)
        throws IOException, IllegalArgumentException, OrekitException {

    // read input parameters
    KeyValueFileParser<ParameterKey> parser = new KeyValueFileParser<ParameterKey>(ParameterKey.class);
    parser.parseInput(new FileInputStream(input));
    TimeScale utc = TimeScalesFactory.getUTC();

    Propagator propagator;/*from   w ww  .j  a va 2 s  .c o  m*/
    if (parser.containsKey(ParameterKey.TLE_LINE1)) {
        propagator = createPropagator(parser.getString(ParameterKey.TLE_LINE1),
                parser.getString(ParameterKey.TLE_LINE2));
    } else {
        propagator = createPropagator(parser.getDate(ParameterKey.ORBIT_CIRCULAR_DATE, utc),
                parser.getDouble(ParameterKey.ORBIT_CIRCULAR_A),
                parser.getDouble(ParameterKey.ORBIT_CIRCULAR_EX),
                parser.getDouble(ParameterKey.ORBIT_CIRCULAR_EY),
                parser.getAngle(ParameterKey.ORBIT_CIRCULAR_I),
                parser.getAngle(ParameterKey.ORBIT_CIRCULAR_RAAN),
                parser.getAngle(ParameterKey.ORBIT_CIRCULAR_ALPHA));
    }

    // simulation properties
    AbsoluteDate start = parser.getDate(ParameterKey.START_DATE, utc);
    double duration = parser.getDouble(ParameterKey.DURATION);
    double step = parser.getDouble(ParameterKey.STEP);
    double angle = parser.getAngle(ParameterKey.ANGULAR_OFFSET);

    // set up a handler to gather all corridor points
    CorridorHandler handler = new CorridorHandler(angle);
    propagator.setMasterMode(step, handler);

    // perform propagation, letting the step handler populate the corridor
    propagator.propagate(start, start.shiftedBy(duration));

    // retrieve the built corridor
    List<CorridorPoint> corridor = handler.getCorridor();

    // create a 7 columns csv file representing the corridor in the user home directory, with
    // date in column 1 (in ISO-8601 format)
    // left limit latitude in column 2 and left limit longitude in column 3
    // center track latitude in column 4 and center track longitude in column 5
    // right limit latitude in column 6 and right limit longitude in column 7
    DecimalFormat format = new DecimalFormat("#00.00000", new DecimalFormatSymbols(Locale.US));
    PrintStream stream = new PrintStream(output);
    for (CorridorPoint p : corridor) {
        stream.println(p.getDate() + separator + format.format(FastMath.toDegrees(p.getLeft().getLatitude()))
                + separator + format.format(FastMath.toDegrees(p.getLeft().getLongitude())) + separator
                + format.format(FastMath.toDegrees(p.getCenter().getLatitude())) + separator
                + format.format(FastMath.toDegrees(p.getCenter().getLongitude())) + separator
                + format.format(FastMath.toDegrees(p.getRight().getLatitude())) + separator
                + format.format(FastMath.toDegrees(p.getRight().getLongitude())));
    }
    stream.close();

}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat currencyFormat(ConfigPriceFormat priceFormat) {
    // khi to currency format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator('.');
    symbols.setGroupingSeparator('.');
    DecimalFormat currencyFormat = new DecimalFormat(pattern, symbols);
    currencyFormat.setGroupingSize(priceFormat.getGroupLength());
    currencyFormat.setMaximumFractionDigits(priceFormat.getPrecision());
    currencyFormat.setMinimumFractionDigits(priceFormat.getRequirePrecision());
    return currencyFormat;
}

From source file:nl.strohalm.cyclos.webservices.rest.AccessRestController.java

/**
 * Returns general data about the authenticated user
 *///from  ww  w .  j av a2 s  .  com
@RequestMapping(value = "access/initialData", method = RequestMethod.GET)
@ResponseBody
public InitialData getInitialData() {
    InitialData data = new InitialData();
    data.setProfile(membersRestController.getMyProfile());
    data.setAccounts(accountsRestController.listAccounts());
    data.setRequireTransactionPassword(isRequireTransactionPassword());

    // Can make payment to member or to system
    TransferTypeSearchParams params = new TransferTypeSearchParams();
    params.setDestination(Destination.MEMBER);
    TransferTypeQuery query = transferTypesRestController.toTransferTypeQuery(params);
    List<TransferType> toMemberTTs = transferTypeService.search(query);
    // Remove the self payments
    for (TransferType tt : toMemberTTs) {
        if (tt.getContext().isSelfPayment()) {
            toMemberTTs.remove(tt);
        }
    }
    params.setDestination(Destination.SYSTEM);
    query = transferTypesRestController.toTransferTypeQuery(params);
    List<TransferType> toSystemTTs = transferTypeService.search(query);
    data.setCanMakeMemberPayments(CollectionUtils.isNotEmpty(toMemberTTs));
    data.setCanMakeSystemPayments(CollectionUtils.isNotEmpty(toSystemTTs));

    // Local settings
    final LocalSettings localSettings = settingsService.getLocalSettings();
    data.setDecimalCount(localSettings.getPrecision().getValue());
    data.setDecimalSeparator(
            new DecimalFormatSymbols(localSettings.getNumberLocale().getLocale()).getDecimalSeparator());
    return data;
}