Java Number Format Pattern getFormattedString4Digits(String number, String pattern)

Here you can find the source of getFormattedString4Digits(String number, String pattern)

Description

get Formatted String Digits

License

Open Source License

Parameter

Parameter Description
number a parameter
pattern a parameter

Declaration

public static String getFormattedString4Digits(String number, String pattern) 

Method Source Code

//package com.java2s;
/*//from  w ww. j a v  a2  s.  c  om
 * Copyright (C) 2010 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.text.DecimalFormat;

public class Main {
    /**
     * @param number
     * @param pattern
     * @return
     * @author KhuongDV Ham format so thuc ve dang co max la 4 chu so thap phan.
     * Trim() so 0 vo nghia
     */
    public static String getFormattedString4Digits(String number, String pattern) {
        double amount = 0;
        try {
            amount = Double.parseDouble(number);
            DecimalFormat formatter = new DecimalFormat(pattern);
            return formatter.format(amount);
        } catch (Exception ex) {
            return number;
        }
    }
}

Related

  1. getFormattedInteger(int n)
  2. getFormattedNumber(int number)
  3. getFormattedNumber(NumberFormat numberFormat, String fieldValue, Class valueClass)
  4. getFormattedNumber(String input)
  5. getFormattedQuantity(String qty, int len, String pad)
  6. getFormatter()
  7. getFormatter()
  8. getFormatter(int precision)
  9. getFormatter(String pattern)