Java Utililty Methods Decimal

List of utility methods to do Decimal

Description

The list of methods to do Decimal are organized into topic(s).

Method

StringdecimalAlign(int width, int precision, String s)
Formats a String representation of a decimal number to a stated precision and total width.
String fraction = "";
String whole = "0.";
int dot = s.lastIndexOf('.');
if (dot >= 0) {
    whole = s.substring(0, dot + 1);
    fraction = s.substring(dot + 1);
if (fraction.length() > precision) {
...
intdecimalDigit(final long value, final int i)
Return a particular digit value from a given number
int result = (int) (Math.abs(value) % Math.pow(10, i));
if (i > 1) {
    result /= Math.pow(10, i - 1);
return result;
intdecimalDigitCount(int num)
decimal Digit Count
if (num < 10)
    return 1;
if (num < 100)
    return 2;
if (num < 1000)
    return 3;
if (num < 10000)
    return 4;
...
StringdecimalDump(final byte[] bytes)
Dumps the byte array into a string as a series of 8bit decimal numbers
StringBuffer buffer = new StringBuffer();
for (byte b : bytes) {
    buffer.append(Byte.toString((byte) (b & SINGLE_BYTE_SIGN_MASK)));
    buffer.append(" ");
return buffer.toString();
floatdecimalPart(float f)
Returns the decimal part of a float, regardless of its sign.
return f - (int) f;
floatdecimalPart(float number)
decimal Part
int integerPart = (int) number;
return number - integerPart;
floatdecimalPlace(float theValue, int theDecimalPlaces)
decimal Place
final float myDecimalPlaceClamp = (float) Math.pow(10, theDecimalPlaces);
return ((int) (theValue * myDecimalPlaceClamp)) / myDecimalPlaceClamp;
doubledecimalPlaces(double value, int precision)
decimal Places
return (double) Math.round(value * Math.pow(10.0D, (double) precision))
        / Math.pow(10.0D, (double) precision);
doubledecimalPlaces(double value, int precision)
Sets a fixed number of digits after the decimal point.
return (double) Math.round(value * Math.pow(10, precision)) / Math.pow(10, precision);
doubledecimalRound(double value, int roundPlaces)
decimal Round
int temp = (int) ((value * Math.pow(10, roundPlaces)));
return (((double) temp) / Math.pow(10, roundPlaces));