Java Double Number Format formatDoubleWithPadding(String value, int length, char pad)

Here you can find the source of formatDoubleWithPadding(String value, int length, char pad)

Description

The total amount in 2 decimal places without decimal point with a leading zero.ie 12.00 = 1200 value = 000000146560

License

Apache License

Parameter

Parameter Description
value a parameter
length a parameter
pad a parameter

Declaration

public static final String formatDoubleWithPadding(String value, int length, char pad) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   ww  w.j a  v  a 2 s.  c  o m
     * The total amount in 2 decimal places without decimal point with a leading
     * zero.ie 12.00 = 1200 value = 000000146560
     * 
     * @param value
     * @param length
     * @param pad
     * @return
     */
    public static final String formatDoubleWithPadding(String value, int length, char pad) {

        String valueStr = value + "";
        int diff = length - valueStr.length();
        StringBuilder strBuilder = new StringBuilder();

        if (diff > 0) {

            while (diff > -1) {
                diff--;
                strBuilder.append(pad);
            }

            strBuilder.append(valueStr);
            valueStr = strBuilder.toString();

            valueStr = valueStr.substring(0, valueStr.indexOf('.'))
                    + valueStr.substring(valueStr.indexOf('.') + 1, valueStr.length());
        }

        return valueStr;
    }
}

Related

  1. formatDoubleInfinity(Double d)
  2. formatDoublePrecise(double source, int decimals, int precision, StringBuffer target)
  3. formatDoubleToFixedLength(String value, int length)
  4. formatDoubleToString(double d)
  5. formatDoubleToString(double n)
  6. getFormat(double d)
  7. getFormat(double value)
  8. getFormatAmount(Double d)
  9. getFormattedNumber(Double number, int decimals, Locale locale)