List of usage examples for java.lang Double toString
public static String toString(double d)
From source file:Main.java
public static String getFormatSize(double size) { double kiloByte = size / 1024; if (kiloByte < 1) { return size + "Byte(s)"; }//w w w .j a v a2s . c o m double megaByte = kiloByte / 1024; if (megaByte < 1) { BigDecimal result1 = new BigDecimal(Double.toString(kiloByte)); return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB"; } double gigaByte = megaByte / 1024; if (gigaByte < 1) { BigDecimal result2 = new BigDecimal(Double.toString(megaByte)); return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB"; } double teraBytes = gigaByte / 1024; if (teraBytes < 1) { BigDecimal result3 = new BigDecimal(Double.toString(gigaByte)); return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB"; } BigDecimal result4 = new BigDecimal(teraBytes); return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB"; }
From source file:Main.java
public static String getFormatSize(double size) { double kiloByte = size / 1024.0D; if (kiloByte < 1.0D) { return size + " B"; // Byte(s) }/*from w w w.j a va 2 s. c om*/ double megaByte = kiloByte / 1024.0D; if (megaByte < 1.0D) { BigDecimal result1 = new BigDecimal(Double.toString(kiloByte)); return result1.setScale(2, 4).toPlainString() + " KB"; } double gigaByte = megaByte / 1024.0D; if (gigaByte < 1.0D) { BigDecimal result2 = new BigDecimal(Double.toString(megaByte)); return result2.setScale(2, 4).toPlainString() + " MB"; } double teraBytes = gigaByte / 1024.0D; if (teraBytes < 1.0D) { BigDecimal result3 = new BigDecimal(Double.toString(gigaByte)); return result3.setScale(2, 4).toPlainString() + " GB"; } BigDecimal result4 = new BigDecimal(teraBytes); return result4.setScale(2, 4).toPlainString() + " TB"; }
From source file:Main.java
public static String getCssColor(int color) { // using %f for the double value would result in a localized string, e.g. 0,12 which // would be an invalid css color string return String.format("rgba(%d,%d,%d,%s)", Color.red(color), Color.green(color), Color.blue(color), Double.toString(Color.alpha(color) / 255.0)); }
From source file:Main.java
/** * Convert a double into a String without scientific notation. * * This is useful for XPath 1.0, which does not understand the scientific notation. *//*from w w w . ja v a 2 s. co m*/ public static String removeScientificNotation(double value) { String result = Double.toString(value); int eIndex = result.indexOf('E'); if (eIndex == -1) { // No scientific notation, return value as is return stripZeros(result); } else { // Scientific notation, convert value // Parse string representation String mantissa = result.substring(0, eIndex); boolean negative = mantissa.charAt(0) == '-'; String sign = negative ? "-" : ""; String mantissa1 = mantissa.substring(negative ? 1 : 0, negative ? 2 : 1); String mantissa2 = mantissa.substring(negative ? 3 : 2); int exponent = Integer.parseInt(result.substring(eIndex + 1)); // Calculate result if (exponent > 0) { // Positive exponent, shift decimal point to the right int mantissa2Length = mantissa2.length(); if (exponent > mantissa2Length) { result = sign + mantissa1 + mantissa2 + nZeros(exponent - mantissa2Length); } else if (exponent == mantissa2Length) { result = sign + mantissa1 + mantissa2; } else { result = sign + mantissa1 + mantissa2.substring(0, exponent) + '.' + mantissa2.substring(exponent); } } else if (exponent == 0) { // Not sure if this can happen result = mantissa; } else { // Negative exponent, shift decimal point to the left result = sign + '0' + '.' + nZeros(-exponent - 1) + mantissa1 + mantissa2; } return stripZeros(result); } }
From source file:Main.java
public static String getFormatSize(double size) { double kiloByte = size / 1024; if (kiloByte < 1) { return size + "B"; }/* ww w . j a va 2 s . com*/ double megaByte = kiloByte / 1024; if (megaByte < 1) { BigDecimal result1 = new BigDecimal(Double.toString(kiloByte)); return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB"; } double gigaByte = megaByte / 1024; if (gigaByte < 1) { BigDecimal result2 = new BigDecimal(Double.toString(megaByte)); return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB"; } double teraBytes = gigaByte / 1024; if (teraBytes < 1) { BigDecimal result3 = new BigDecimal(Double.toString(gigaByte)); return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB"; } BigDecimal result4 = new BigDecimal(teraBytes); return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB"; }
From source file:LongToMSec.java
/** Convert a long ("time_t") to seconds and milliseconds */ public static String msToSecs(long t) { // The first attempt fails for the case "1024" //return t/1000 + "." + t%1000; return Double.toString(t / 1000D); }
From source file:Main.java
public static void addDoubleProperty(Document document, Element parent, String name, double value) { addPropertyNode(document, parent, name).setAttribute(DOUBLE_ATTR, Double.toString(value)); }
From source file:Main.java
public static void MercatorToBD(double mercatorX, double mercatorY) { CbdX = mercatorY / 20037508.34 * 180; CbdX = 180 / Math.PI * (2 * Math.atan(Math.exp(CbdX * Math.PI / 180)) - Math.PI / 2); CbdY = mercatorX / 20037508.34 * 180; Log.d("CustomerActivity", "x" + Double.toString(CbdX)); Log.d("CustomerActivity", "y" + Double.toString(CbdY)); }
From source file:Main.java
public static void addFloatProperty(Document document, Element parent, String name, double value) { addPropertyNode(document, parent, name).setAttribute(FLOAT_ATTR, Double.toString(value)); }
From source file:Main.java
public static double divide(double v1, double v2, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); }//from www. j a v a2s . c o m BigDecimal b = new BigDecimal(Double.toString(v1)); BigDecimal one = new BigDecimal(v2); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); }