Java BigInteger Format formatTime(BigInteger femto)

Here you can find the source of formatTime(BigInteger femto)

Description

format Time

License

Open Source License

Declaration

public static String formatTime(BigInteger femto) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;

public class Main {
    public static String formatTime(BigInteger femto) {
        if (femto.equals(BigInteger.ZERO))
            return "0";
        StringBuilder time = new StringBuilder(femto.toString());
        String[] units = { "fs", "ps", "ns", "us", "ms", "sec", "ksec", "Msec" };
        for (String unit : units) {
            if (time.length() <= 3 || !time.toString().endsWith("000"))
                return time + " " + unit;
            time.setLength(time.length() - 3);
        }/*from w  w w . jav a2s. com*/
        return time + " " + units[units.length - 1];
    }
}

Related

  1. formatBigInteger(BigInteger bi, int length)
  2. formatBigIntegerBinary(final long value, byte[] buf, final int offset, final int length, final boolean negative)
  3. formatSerialNumber(BigInteger bi)
  4. formatSerialNumber(final BigInteger serial)
  5. formatSize(BigInteger size)