Example usage for java.text DecimalFormatSymbols getDecimalSeparator

List of usage examples for java.text DecimalFormatSymbols getDecimalSeparator

Introduction

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

Prototype

public char getDecimalSeparator() 

Source Link

Document

Gets the character used for decimal sign.

Usage

From source file:com.marand.thinkmed.medications.business.impl.TherapyDisplayProvider.java

public String getFormattedDecimalValue(final String decimalValue, final Locale locale, final boolean bold) {
    if (decimalValue == null || locale == null) {
        return "";
    }//from  w  w  w.j  a v  a  2s  .  c  o  m
    final DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
    final Character decimalSeparator = dfs.getDecimalSeparator();
    final String splitDelimiter = decimalSeparator.equals(new Character('.')) ? "\\." : ",";

    String formattedValue = decimalValue;
    final Pattern p = Pattern.compile("\\d+" + splitDelimiter + "\\d+"); // or ("[0-9]+" + splitDelimiter + "[0-9]+") ?
    final Matcher m = p.matcher(formattedValue);
    while (m.find()) {
        final String[] decimalNumbers = m.group().split(splitDelimiter);
        if (decimalNumbers.length == 2) {
            formattedValue = formattedValue.replaceAll(m.group(),
                    decimalNumbers[0] + splitDelimiter + createSpannedValue(decimalNumbers[1],
                            "TextDataSmallerDecimal" + (bold ? " bold" : ""), false));
        }
    }
    return formattedValue;
}

From source file:com.thomasokken.free42.Free42Activity.java

/**
 * shell_decimal_point()//from w ww .jav  a2 s.  co m
 * Returns 0 if the host's locale uses comma as the decimal separator;
 * returns 1 if it uses dot or anything else.
 * Used to initialize flag 28 on hard reset.
 */
public int shell_decimal_point() {
    DecimalFormat df = new DecimalFormat();
    DecimalFormatSymbols dfsym = df.getDecimalFormatSymbols();
    return dfsym.getDecimalSeparator() == ',' ? 0 : 1;
}

From source file:org.sakaiproject.tool.messageforums.DiscussionForumTool.java

public boolean isFewerDigit(String validateString) {
    NumberFormat numberFormat = DecimalFormat.getInstance(new ResourceLoader().getLocale());
    DecimalFormatSymbols dfs = ((DecimalFormat) numberFormat).getDecimalFormatSymbols();
    if (validateString.lastIndexOf(dfs.getDecimalSeparator()) >= 0) {
        String subString = validateString.substring(validateString.lastIndexOf(dfs.getDecimalSeparator()));
        if (subString != null && subString.length() > 3)
            return false;
    }/*from w w  w  .j av a 2 s .  co m*/

    return true;
}