Java Utililty Methods Decimal

List of utility methods to do Decimal

  1. HOME
  2. Java
  3. D
  4. Decimal

Description

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

Method

String decimalAlign(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) {
...
int decimalDigit(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;
int decimalDigitCount(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;
...
String decimalDump(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();
float decimalPart(float f)
Returns the decimal part of a float, regardless of its sign.
return f - (int) f;
float decimalPart(float number)
decimal Part
int integerPart = (int) number;
return number - integerPart;
float decimalPlace(float theValue, int theDecimalPlaces)
decimal Place
final float myDecimalPlaceClamp = (float) Math.pow(10, theDecimalPlaces);
return ((int) (theValue * myDecimalPlaceClamp)) / myDecimalPlaceClamp;
double decimalPlaces(double value, int precision)
decimal Places
return (double) Math.round(value * Math.pow(10.0D, (double) precision))
 / Math.pow(10.0D, (double) precision);
double decimalPlaces(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);
double decimalRound(double value, int roundPlaces)
decimal Round
int temp = (int) ((value * Math.pow(10, roundPlaces)));
return (((double) temp) / Math.pow(10, roundPlaces));


AltStyle によって変換されたページ (->オリジナル) /