Java Double Number Format formatDoubleToFixedLength(String value, int length)

Here you can find the source of formatDoubleToFixedLength(String value, int length)

Description

Right justified with 2 decimal places.Procced with zeros?

License

Apache License

Parameter

Parameter Description
value a parameter
length a parameter

Declaration

public static final String formatDoubleToFixedLength(String value, int length) 

Method Source Code

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

public class Main {
    /**// www.  j  av a 2 s.c o m
     * Right justified with 2 decimal places.Procced with zeros? For Revenue
     * material sale price would be populated format 12.05 to length 12 digits
     * value = "       12.05"
     * 
     * @param value
     * @param length
     * @return
     */
    public static final String formatDoubleToFixedLength(String value, int length) {

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

        if (diff > 0) {

            while (diff > 0) {
                diff--;
                strBuilder.append(" ");
            }

            strBuilder.append(valueStr);

            valueStr = strBuilder.toString();
        }

        return valueStr;
    }
}

Related

  1. formatDoubleAsString(double num, int n)
  2. formatDoubleFast(double source, int decimals, int precision, StringBuffer target)
  3. formatDoubleForDecimalPlaces(double d, int decimalcount)
  4. formatDoubleInfinity(Double d)
  5. formatDoublePrecise(double source, int decimals, int precision, StringBuffer target)
  6. formatDoubleToString(double d)
  7. formatDoubleToString(double n)
  8. formatDoubleWithPadding(String value, int length, char pad)
  9. getFormat(double d)