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:de.perdian.commons.lang.conversion.impl.converters.AbstractNumberFormatConverter.java

@Override
protected NumberFormat resolveDefaultFormat(Locale locale) {
    return Optional.ofNullable(this.getPattern())
            .<NumberFormat>map(pattern -> new DecimalFormat(pattern, new DecimalFormatSymbols(locale)))
            .orElseGet(NumberFormat::getInstance);
}

From source file:org.webguitoolkit.ui.controls.util.conversion.NumberAllConverter.java

/**
 * conmvert from any number object into string using the format pattern.
 *///from  w  w  w  .  j a  v  a 2s  .  co  m
public Object convert(Class type, Object value) {
    if (value == null)
        return "";
    if (value instanceof String)
        return value; // TODO fix bug in parse
    if (type != String.class || !(value instanceof Number)) {
        throw new WGTException("can only convert into string");
    }
    formatter = new DecimalFormat(pattern, new DecimalFormatSymbols(TextService.getLocale()));

    return formatter.format(value);
}

From source file:thymeleafsandbox.springjsp.web.conversion.NumberFormatter.java

public String print(final Number object, final Locale locale) {
    final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getNumberInstance();
    final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
    symbols.setGroupingSeparator('*');
    numberFormat.setDecimalFormatSymbols(symbols);
    return numberFormat.format(object);
}

From source file:by.creepid.docsreporter.context.DocContextProcessorTest.java

public DocContextProcessorTest() {
    Locale locale = Locale.getDefault();
    decimalFormatter = (DecimalFormat) NumberFormat.getInstance(locale);
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
    symbols.setDecimalSeparator(',');
    symbols.setGroupingSeparator(' ');
    decimalFormatter.setDecimalFormatSymbols(symbols);

    dateFormat = new SimpleDateFormat("dd.MM.yyyy");
}

From source file:com.cloudmade.api.geometry.Point.java

@Override
public String toString() {
    DecimalFormat formatter = new DecimalFormat("0.#####", new DecimalFormatSymbols(Locale.US));
    return formatter.format(lat) + "," + formatter.format(lng);
}

From source file:org.nuxeo.ecm.platform.video.storyboard.TextItem.java

public TextItem(DocumentModel doc, String basePropertyPath, int position)
        throws PropertyException, ClientException {
    this.doc = doc;
    this.position = position;
    String propertyPath = basePropertyPath + "/" + position;
    try {//from  ww w.jav  a 2  s  .co m
        tc = doc.getProperty(propertyPath + "/timecode").getValue(Double.class);
        if (tc != null) {
            double hours = Math.floor(tc / 3600);
            double minutes = Math.floor((tc / 60) - (hours * 60));
            double seconds = tc - (hours * 3600) - (minutes * 60);
            DecimalFormat decimalFormater = new DecimalFormat("00");
            DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
            DecimalFormat secondsformatter = new DecimalFormat("00.000", symbols);
            timecode = String.format("%s:%s:%s", decimalFormater.format(hours), decimalFormater.format(minutes),
                    secondsformatter.format(seconds));
        }
    } catch (Exception e) {
        log.warn(e);
    }
    text = doc.getProperty(VideoInfoConstants.TEXT_PROPERTY + "/" + position + "/text").getValue(String.class);
}

From source file:no.kantega.publishing.common.data.attributes.NumberAttribute.java

public String getValue(String format, Locale locale) {

    if (value == null) {
        return "";
    }// w w  w.  java 2  s . c  om
    if (format == null || format.length() == 0) {
        return getValue();
    }

    NumberFormat formatter;

    if (locale != null) {
        formatter = new DecimalFormat(format, new DecimalFormatSymbols(locale));
    } else {
        formatter = new DecimalFormat(format);
    }

    return formatter.format(Double.parseDouble(value));
}

From source file:org.lpe.common.util.LpeNumericUtils.java

/**
 * Formats a <code>double</code> value into a <code>String</code> with
 * <i>d</i> digits after decimal point.
 * /*from w ww. ja  va  2s. co m*/
 * @param v
 *            value to format
 * @param d
 *            number of digits
 * @return formatted String
 */
public static String dFormat(double v, int d) {
    String pattern = "0";

    for (int i = 0; i < d; i++) {
        if (i == 0) {
            pattern += ".";
        }

        pattern += "0";
    }

    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    DecimalFormat format = new DecimalFormat(pattern, otherSymbols);
    return format.format(v);
}

From source file:org.nuxeo.ecm.platform.video.storyboard.SubtitleItem.java

public SubtitleItem(DocumentModel doc, String basePropertyPath, int position)
        throws PropertyException, ClientException {
    this.doc = doc;
    this.position = position;
    String propertyPath = basePropertyPath + "/" + position;
    try {/*from   www  .j  a  v  a  2 s .  co  m*/
        tcStart = doc.getProperty(propertyPath + "/start").getValue(Double.class);
        if (tcStart != null) {
            double hours = Math.floor(tcStart / 3600);
            double minutes = Math.floor((tcStart / 60) - (hours * 60));
            double seconds = tcStart - (hours * 3600) - (minutes * 60);
            DecimalFormat decimalFormater = new DecimalFormat("00");
            DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
            DecimalFormat secondsformatter = new DecimalFormat("00.000", symbols);
            start = String.format("%s:%s:%s", decimalFormater.format(hours), decimalFormater.format(minutes),
                    secondsformatter.format(seconds));
        }
        tcEnd = doc.getProperty(propertyPath + "/end").getValue(Double.class);
        if (tcEnd != null) {
            double hours = Math.floor(tcEnd / 3600);
            double minutes = Math.floor((tcEnd / 60) - (hours * 60));
            double seconds = tcEnd - (hours * 3600) - (minutes * 60);
            DecimalFormat decimalFormater = new DecimalFormat("00");
            DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
            DecimalFormat secondsformatter = new DecimalFormat("00.000", symbols);
            end = String.format("%s:%s:%s", decimalFormater.format(hours), decimalFormater.format(minutes),
                    secondsformatter.format(seconds));
        }
    } catch (Exception e) {
        log.warn(e);
    }
    text = doc.getProperty(VideoInfoConstants.SUBTITLE_PROPERTY + "/" + position + "/text")
            .getValue(String.class);
}

From source file:org.webguitoolkit.ui.controls.util.conversion.SelectFloatConverter.java

public SelectFloatConverter(Float emptyValue, int fractionDigit) {
    this.emptyValue = emptyValue;
    // formatter with defined conversion rules, not depending on the Locale.getdeault(), which is dependent 
    // on the installation.
    formatter = new DecimalFormat("#", new DecimalFormatSymbols(Locale.ENGLISH));
    formatter.setMaximumFractionDigits(fractionDigit);
    formatter.setMinimumFractionDigits(fractionDigit);
}