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:op.tools.SYSTools.java

public static String assimilateDecimalSeparators(String in) {
    if (SYSTools.catchNull(in).isEmpty())
        return in;

    char sep = new DecimalFormatSymbols(Locale.getDefault(Locale.Category.FORMAT)).getDecimalSeparator();
    char replace = '.';

    if (sep == '.') {
        replace = ',';
    }/*from w w w. ja v a2  s  .c  o  m*/

    return in.replace(replace, sep);
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Returns a latitude string representation from a value.
 * /*from   w ww. j a  v a  2  s.c  o m*/
 * @param value value of the latitude
 * 
 * @return a string representation of the latitude
 */
public static String getLatAsString(double value) {
    DecimalFormat decimalFormat = new DecimalFormat(LATLON_DECIMALFORMAT, new DecimalFormatSymbols(Locale.US));
    return decimalFormat.format(value);
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Returns a normalize latitude string representation (Normalize the latitude to lie between +/-90).
 * /*w ww.  j  a  v a  2 s .c  om*/
 * @param value value of the latitude
 * 
 * @return a string representation of the latitude
 */
public static String getNormalizeLatAsString(double value) {
    DecimalFormat decimalFormat = new DecimalFormat(LATLON_DECIMALFORMAT, new DecimalFormatSymbols(Locale.US));
    return decimalFormat.format(LatLonPointImpl.latNormal(value));
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Returns a longitude string representation (no normalization) from a value.
 * //from w  w w . j a  va  2s  . c  om
 * @param value value of the longitude
 * 
 * @return a string representation of the longitude
 */
public static String getLonAsString(double value) {
    DecimalFormat decimalFormat = new DecimalFormat(LATLON_DECIMALFORMAT, new DecimalFormatSymbols(Locale.US));
    return decimalFormat.format(value);
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Returns a normalize longitude string representation (Normalize the longitude to lie between +/-180).
 * /*from w  w w .j a v a  2  s .c  o  m*/
 * @param value value of the longitude
 * 
 * @return a string representation of the longitude
 */
public static String getNormalizeLonAsString(double value) {
    DecimalFormat decimalFormat = new DecimalFormat(LATLON_DECIMALFORMAT, new DecimalFormatSymbols(Locale.US));
    return decimalFormat.format(LatLonPointImpl.lonNormal(value));
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Returns a normalize longitude string representation (Normalize the longitude longitude into the range
 * [0, 360]).//from  ww  w .  j  a  v a 2 s.c  o m
 * 
 * @param value value of the longitude
 * 
 * @return a string representation of the longitude
 */
public static String getNormalizeLon360AsString(double value) {
    DecimalFormat decimalFormat = new DecimalFormat(LATLON_DECIMALFORMAT, new DecimalFormatSymbols(Locale.US));
    return decimalFormat.format(LatLonPointImpl.lonNormal360(value));
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Returns a GeoX string representation from a value.
 * // www .j av  a 2 s.  c  o  m
 * @param value value of the GeoX
 * 
 * @return a string representation of the GeoX
 */
public static String getStandardGeoXYAsString(double value) {
    DecimalFormat decimalFormat = new DecimalFormat(GEOXY_DECIMALFORMAT, new DecimalFormatSymbols(Locale.US));
    return decimalFormat.format(value);
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Returns a Z string representation from a value.
 * //from  w w w .  ja v  a2s  . c  o  m
 * @param value value of the Z
 * @param format format string of the Z
 * 
 * @return a string representation of the Z
 */
public static String getStandardZAsFmtString(double value, String format) {
    DecimalFormat decimalFormat = new DecimalFormat(format, new DecimalFormatSymbols(Locale.US));
    if (value == 0.0) {
        return NetCdfReader.Z_ZEROVALUE;
    }
    return decimalFormat.format(value);
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Gets the standard z as string./*  w w w .ja v a2s  .c o  m*/
 * 
 * @param value the value
 * @param roundingMode the rounding mode
 * @param desiredDecimalNumberDigits the desired decimal number of digits
 * 
 * @return the standard z as fmt string
 */
public static String getStandardZAsString(double value, RoundingMode roundingMode,
        int desiredDecimalNumberDigits) {

    int in = (int) (value);
    double frac = value - in;

    if (frac == 0d) {
        return NetCdfReader.getStandardZAsString(value);
    }

    DecimalFormat decimalFormat = new DecimalFormat();

    decimalFormat.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    decimalFormat.setGroupingUsed(false);
    decimalFormat.setMinimumFractionDigits(desiredDecimalNumberDigits);
    decimalFormat.setMaximumFractionDigits(desiredDecimalNumberDigits);

    decimalFormat.setRoundingMode(roundingMode);

    return decimalFormat.format(value);
}

From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java

public static String num2str(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    String sRC = "";
    switch (ArgList.length) {
    case 0:/*from   w w w.j a  v  a  2 s .  c om*/
        throw new RuntimeException("The function call num2str requires at least 1 argument.");
    case 1:
        try {
            if (isNull(ArgList[0]))
                return null;
            else if (isUndefined(ArgList[0]))
                return (String) undefinedValue;
            double sArg1 = (Double) ArgList[0];
            if (Double.isNaN(sArg1))
                throw new RuntimeException("The first Argument must be a Number.");
            DecimalFormat formatter = new DecimalFormat();
            sRC = formatter.format(sArg1);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("Could not apply the given format on the number : " + e.getMessage());
        }
        break;
    case 2:
        try {
            if (isNull(ArgList, new int[] { 0, 1 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1 }))
                return (String) undefinedValue;
            double sArg1 = (Double) ArgList[0];
            if (Double.isNaN(sArg1))
                throw new RuntimeException("The first Argument must be a Number.");
            String sArg2 = (String) ArgList[1];
            DecimalFormat formatter = new DecimalFormat(sArg2);
            sRC = formatter.format(sArg1);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("Could not apply the given format on the number : " + e.getMessage());
        }
        break;
    case 3:
        try {
            if (isNull(ArgList, new int[] { 0, 1, 2 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1, 2 }))
                return (String) undefinedValue;
            double sArg1 = (Double) ArgList[0];
            if (Double.isNaN(sArg1))
                throw new RuntimeException("The first Argument must be a Number.");
            String sArg2 = (String) ArgList[1];
            String sArg3 = (String) ArgList[2];
            if (sArg3.length() == 2) {
                DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale(sArg3.toLowerCase()));
                DecimalFormat formatter = new DecimalFormat(sArg2, dfs);
                sRC = formatter.format(sArg1);
            }
        } catch (Exception e) {
            throw new RuntimeException(e.toString());
        }
        break;
    default:
        throw new RuntimeException("The function call num2str requires 1, 2, or 3 arguments.");
    }

    return sRC;
}