Java String Leading Character addLeadingZerosToNumber(long number, int length)

Here you can find the source of addLeadingZerosToNumber(long number, int length)

Description

add Leading Zeros To Number

License

Apache License

Declaration

public static String addLeadingZerosToNumber(long number, int length) 

Method Source Code

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

public class Main {
    public static String addLeadingZerosToNumber(long number, int length) {
        //the digits in the "number" is greater than or equal to the "length"
        if (length <= ((int) Math.log10(number) + 1))
            return String.valueOf(number);

        return String.format("%0" + length + "d", number);
    }/*from w  w  w  . jav a  2  s  . com*/
}

Related

  1. addLeadingZeros(Object number, int places)
  2. addLeadingZeros(String deweyCallNum)
  3. addLeadingZeros(String number, int maxDigits)
  4. addLeadingZeros(String s, int nZeros)
  5. addLeadingZeros(String str)