Here you can find the source of getFormattedString4Digits(String number, String pattern)
Parameter | Description |
---|---|
number | a parameter |
pattern | a parameter |
public static String getFormattedString4Digits(String number, String pattern)
//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; } } }