Java Locale Format formatValues(double x, double y)

Here you can find the source of formatValues(double x, double y)

Description

format Values

License

Open Source License

Declaration

public static String formatValues(double x, double y) 

Method Source Code


//package com.java2s;
/*  This file is part of Openrouteservice.
 *
 *  Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the 
 *  GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 
 *  of the License, or (at your option) any later version.
    //w  w  w. java2 s .  c o m
 *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *  See the GNU Lesser General Public License for more details.
    
 *  You should have received a copy of the GNU Lesser General Public License along with this library; 
 *  if not, see <https://www.gnu.org/licenses/>.  
 */

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

public class Main {
    private static final ThreadLocal<NumberFormat> nfCoordRound = new ThreadLocal<NumberFormat>() {
        @Override
        protected NumberFormat initialValue() {
            NumberFormat nf = new DecimalFormat("#0");
            nf = NumberFormat.getNumberInstance(Locale.US);
            nf.setMaximumFractionDigits(7);
            nf.setMinimumFractionDigits(7);
            nf.setRoundingMode(RoundingMode.HALF_UP);
            return nf;
        }
    };

    public static String formatValues(double x, double y) {
        NumberFormat nf = nfCoordRound.get();
        return nf.format(x) + " " + nf.format(y);
    }
}

Related

  1. formattedToDouble(String str, Locale loc)
  2. formatTime(Calendar calendar, String format)
  3. formatTime(final double theTime)
  4. formatTo(StringBuilder buf, int[] d, String sep)
  5. formatToString(double num, int decPlaces)
  6. formatZahl(Number nZahl, int iNachkommastellen, Locale locale)