Example usage for java.lang Double toString

List of usage examples for java.lang Double toString

Introduction

In this page you can find the example usage for java.lang Double toString.

Prototype

public static String toString(double d) 

Source Link

Document

Returns a string representation of the double argument.

Usage

From source file:nz.co.wholemeal.christchurchmetro.Stop.java

/**
 * Returns an ArrayList of all the stops on a given route within the square
 * bounded by the two GeoPoints./* ww  w  .ja v  a2  s.c o  m*/
 */
public static ArrayList<Stop> getAllWithinBounds(Context context, GeoPoint topLeft, GeoPoint bottomRight,
        String routeTag) {

    String topLat = Double.toString(topLeft.getLatitudeE6() / 1E6);
    String topLon = Double.toString(topLeft.getLongitudeE6() / 1E6);
    String bottomLat = Double.toString(bottomRight.getLatitudeE6() / 1E6);
    String bottomLon = Double.toString(bottomRight.getLongitudeE6() / 1E6);

    String query = "SELECT p.platform_tag, p.platform_number, p.name, "
            + "p.road_name, p.latitude, p.longitude FROM platforms p" + " WHERE p.platform_tag IN"
            + "   (SELECT platform_tag FROM patterns_platforms" + "   WHERE route_tag = '" + routeTag + "')"
            + " AND p.latitude < " + topLat + " AND p.longitude > " + topLon + " AND p.latitude > " + bottomLat
            + " AND p.longitude < " + bottomLon;

    return doArrayListQuery(context, query);
}

From source file:de.kirchnerei.bicycle.battery.BatteryEditFragment.java

private void updateAverageSpeed(int averageSpeed) {
    String value = Double.toString((double) averageSpeed / 10);
    item.setAverageSpeed(averageSpeed);/* w  w  w  . j a v  a2 s  .  com*/
    mAverageSpeed.setText(averageSpeed != 0 ? value : "");
}

From source file:com.wormsim.tracking.TrackedDouble.java

@Override
public String toMeanString() {
    return Double.toString(this.getMean());
}

From source file:com.sk89q.craftbook.util.ICUtil.java

public static void parseSignFlags(LocalPlayer player, ChangedSign sign) {

    for (int i = 2; i < 4; i++) {

        if (sign.getLine(i).contains("[off]")) {

            if (CraftBookPlugin.plugins.getWorldEdit() == null) {
                sign.setLine(i, StringUtils.replace(sign.getLine(i), "[off]", ""));
                player.printError("worldedit.ic.notfound");
            } else {
                if (CraftBookPlugin.plugins.getWorldEdit()
                        .getSelection(((BukkitPlayer) player).getPlayer()) != null
                        && CraftBookPlugin.plugins.getWorldEdit()
                                .getSelection(((BukkitPlayer) player).getPlayer())
                                .getRegionSelector() != null) {

                    RegionSelector selector = CraftBookPlugin.plugins.getWorldEdit()
                            .getSelection(((BukkitPlayer) player).getPlayer()).getRegionSelector();

                    try {
                        if (selector instanceof CuboidRegionSelector) {

                            Vector centre = selector.getRegion().getMaximumPoint()
                                    .add(selector.getRegion().getMinimumPoint());

                            centre = centre.divide(2);

                            Vector offset = centre.subtract(sign.getBlockVector());

                            String x, y, z;

                            x = Double.toString(offset.getX());
                            if (x.endsWith(".0"))
                                x = StringUtils.replace(x, ".0", "");

                            y = Double.toString(offset.getY());
                            if (y.endsWith(".0"))
                                y = StringUtils.replace(y, ".0", "");

                            z = Double.toString(offset.getZ());
                            if (z.endsWith(".0"))
                                z = StringUtils.replace(z, ".0", "");

                            sign.setLine(i,
                                    StringUtils.replace(sign.getLine(i), "[off]", "&" + x + ":" + y + ":" + z));
                        } else if (selector instanceof SphereRegionSelector) {

                            Vector centre = ((SphereRegionSelector) selector).getRegion().getCenter();

                            Vector offset = centre.subtract(sign.getBlockVector());

                            String x, y, z;

                            x = Double.toString(offset.getX());
                            if (x.endsWith(".0"))
                                x = StringUtils.replace(x, ".0", "");

                            y = Double.toString(offset.getY());
                            if (y.endsWith(".0"))
                                y = StringUtils.replace(y, ".0", "");

                            z = Double.toString(offset.getZ());
                            if (z.endsWith(".0"))
                                z = StringUtils.replace(z, ".0", "");

                            sign.setLine(i,
                                    StringUtils.replace(sign.getLine(i), "[off]", "&" + x + ":" + y + ":" + z));
                        } else { // Unsupported.
                            sign.setLine(i, StringUtils.replace(sign.getLine(i), "[off]", ""));
                            player.printError("worldedit.ic.unsupported");
                        }/*  w w  w  .  java2 s . c  om*/
                    } catch (IncompleteRegionException e) {
                        player.printError("worldedit.ic.noselection");
                    }
                } else {
                    player.printError("worldedit.ic.noselection");
                }
            }
        }

        if (sign.getLine(i).contains("[rad]")) {

            if (CraftBookPlugin.plugins.getWorldEdit() == null) {
                sign.setLine(i, StringUtils.replace(sign.getLine(i), "[rad]", ""));
                player.printError("worldedit.ic.notfound");
            } else {

                if (CraftBookPlugin.plugins.getWorldEdit()
                        .getSelection(((BukkitPlayer) player).getPlayer()) != null
                        && CraftBookPlugin.plugins.getWorldEdit()
                                .getSelection(((BukkitPlayer) player).getPlayer())
                                .getRegionSelector() != null) {

                    RegionSelector selector = CraftBookPlugin.plugins.getWorldEdit()
                            .getSelection(((BukkitPlayer) player).getPlayer()).getRegionSelector();

                    try {
                        if (selector instanceof CuboidRegionSelector) {

                            String x, y, z;

                            x = Double.toString(Math.abs(selector.getRegion().getMaximumPoint().getX()
                                    - selector.getRegion().getMinimumPoint().getX()) / 2);
                            if (x.endsWith(".0"))
                                x = StringUtils.replace(x, ".0", "");

                            y = Double.toString(Math.abs(selector.getRegion().getMaximumPoint().getY()
                                    - selector.getRegion().getMinimumPoint().getY()) / 2);
                            if (y.endsWith(".0"))
                                y = StringUtils.replace(y, ".0", "");

                            z = Double.toString(Math.abs(selector.getRegion().getMaximumPoint().getZ()
                                    - selector.getRegion().getMinimumPoint().getZ()) / 2);
                            if (z.endsWith(".0"))
                                z = StringUtils.replace(z, ".0", "");

                            sign.setLine(i,
                                    StringUtils.replace(sign.getLine(i), "[rad]", x + "," + y + "," + z));
                        } else if (selector instanceof SphereRegionSelector) {

                            String x;

                            double amounts = ((EllipsoidRegion) selector.getRegion()).getRadius().getX();

                            x = Double.toString(amounts);
                            if (x.endsWith(".0"))
                                x = StringUtils.replace(x, ".0", "");

                            sign.setLine(i, StringUtils.replace(sign.getLine(i), "[rad]", x));
                        } else { // Unsupported.
                            sign.setLine(i, StringUtils.replace(sign.getLine(i), "[rad]", ""));
                            player.printError("worldedit.ic.unsupported");
                        }
                    } catch (IncompleteRegionException e) {
                        player.printError("worldedit.ic.noselection");
                    }
                } else {
                    player.printError("worldedit.ic.noselection");
                }
            }
        }
    }

    sign.update(false);
}

From source file:ml.shifu.shifu.udf.PopulationCounterUDF.java

private String toStatsText(String unit, double mean, double missingRate, long totalInstCnt) {
    return unit + "^" + Double.toString(mean) + "^" + Double.toString(missingRate) + "^"
            + Long.toString(totalInstCnt);
}

From source file:desmoj.core.dist.ContDistBeta.java

/**
 * Returns the next sample from this distribution. The value depends upon
 * the seed, the number of values taken from the stream by using this method
 * before and the alpha and beta parameters specified for this distribution.
 * //from   w  w w . j  a v a 2  s.c  o m
 * @return Double : The next Beta distributed sample from this distribution.
 */
public Double sample() {

    double newSample = -1; //
    double randomNumber1 = randomGenerator.nextDouble();
    double randomNumber2 = randomGenerator.nextDouble();
    org.apache.commons.math.distribution.GammaDistribution gammadist1 = new org.apache.commons.math.distribution.GammaDistributionImpl(
            alpha, 1);
    org.apache.commons.math.distribution.GammaDistribution gammadist2 = new org.apache.commons.math.distribution.GammaDistributionImpl(
            beta, 1);
    incrementObservations(); // increase count of samples

    if (isAntithetic()) {

        try {
            double gammaval1 = gammadist1.inverseCumulativeProbability(1 - randomNumber1);
            double gammaval2 = gammadist2.inverseCumulativeProbability(1 - randomNumber2);
            newSample = gammaval1 / (gammaval1 + gammaval2);
        } catch (MathException e) {
        }
    } else {
        try {
            double gammaval1 = gammadist1.inverseCumulativeProbability(randomNumber1);
            double gammaval2 = gammadist2.inverseCumulativeProbability(randomNumber2);
            newSample = gammaval1 / (gammaval1 + gammaval2);
        } catch (MathException e) {
        }
    }

    if (this.currentlySendTraceNotes())
        this.traceLastSample(Double.toString(newSample));

    return newSample;
}

From source file:com.astifter.circatext.OpenWeatherMapJSONParser.java

@Override
public URL getURL(android.location.Location location, String cityName) {
    // api.openweathermap.org/data/2.5/weather?lat=35&lon=139
    String BASE_URL = "http://api.openweathermap.org/data/2.5/weather?units=metric&APPID=d9b53ed2098c82758e054eec0d9112d5&";
    String lat = "lat=" + Double.toString(location.getLatitude());
    String lon = "lon=" + Double.toString(location.getLongitude());
    try {//from   w  w  w  .j  a  v a2 s  . c o m
        return new URL(BASE_URL + lat + "&" + lon);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.igormaznitsa.ideamindmap.facet.InMemoryPreferenceNode.java

@Override
public double getDouble(String key, double def) {
    final String value = get(key, Double.toString(def));
    try {//from   w w w . jav  a2 s  .  c  o  m
        return Double.parseDouble(value);
    } catch (NumberFormatException ex) {
        return def;
    }
}

From source file:de.huxhorn.sulky.plist.impl.PropertyListWriter.java

private void writeValue(XMLStreamWriter writer, Object value) throws XMLStreamException {
    if (value == null) {
        return;/* w w w  .j  a v a  2s  . c  o  m*/
    }
    if (value instanceof String) {
        StaxUtilities.writeSimpleTextNode(writer, null, null, STRING_NODE, (String) value);
        return;
    }
    if (value instanceof Boolean) {
        Boolean bool = (Boolean) value;
        if (bool) {
            StaxUtilities.writeEmptyElement(writer, null, null, TRUE_NODE);
        } else {
            StaxUtilities.writeEmptyElement(writer, null, null, FALSE_NODE);
        }
        return;
    }

    if (value instanceof Character) {
        StaxUtilities.writeSimpleTextNode(writer, null, null, STRING_NODE, value.toString());
        return;
    }

    if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
        Number number = (Number) value;
        StaxUtilities.writeSimpleTextNode(writer, null, null, INTEGER_NODE, Long.toString(number.longValue()));
        return;
    }

    if (value instanceof Float || value instanceof Double) {
        Number number = (Number) value;
        StaxUtilities.writeSimpleTextNode(writer, null, null, REAL_NODE, Double.toString(number.doubleValue()));
        return;
    }

    if (value instanceof byte[]) {
        byte[] data = (byte[]) value;
        writeData(writer, data);
        return;
    }

    if (value instanceof Date) {
        Date date = (Date) value;
        writeDate(writer, date);
        return;
    }

    if (value instanceof Map) {
        Map map = (Map) value;
        writeDict(writer, map);
        return;
    }

    if (value instanceof Collection) {
        Collection collection = (Collection) value;
        writeArray(writer, collection);
        return;
    }

    Class valueClass = value.getClass();
    if (valueClass.isArray()) {
        List<?> list;
        // we handled byte[] already
        if (value instanceof short[]) {
            short[] array = (short[]) value;
            ArrayList<Short> arrayList = new ArrayList<Short>(array.length);
            for (short v : array) {
                arrayList.add(v);
            }
            list = arrayList;
        } else if (valueClass == int[].class) {
            int[] array = (int[]) value;
            ArrayList<Integer> arrayList = new ArrayList<Integer>(array.length);
            for (int v : array) {
                arrayList.add(v);
            }
            list = arrayList;
        } else if (valueClass == long[].class) {
            long[] array = (long[]) value;
            ArrayList<Long> arrayList = new ArrayList<Long>(array.length);
            for (long v : array) {
                arrayList.add(v);
            }
            list = arrayList;
        } else if (valueClass == float[].class) {
            float[] array = (float[]) value;
            ArrayList<Float> arrayList = new ArrayList<Float>(array.length);
            for (float v : array) {
                arrayList.add(v);
            }
            list = arrayList;
        } else if (valueClass == double[].class) {
            double[] array = (double[]) value;
            ArrayList<Double> arrayList = new ArrayList<Double>(array.length);
            for (double v : array) {
                arrayList.add(v);
            }
            list = arrayList;
        } else if (valueClass == boolean[].class) {
            boolean[] array = (boolean[]) value;
            ArrayList<Boolean> arrayList = new ArrayList<Boolean>(array.length);
            for (boolean v : array) {
                arrayList.add(v);
            }
            list = arrayList;
        } else if (valueClass == char[].class) {
            char[] array = (char[]) value;
            String s = new String(array);
            StaxUtilities.writeSimpleTextNode(writer, null, null, STRING_NODE, s);
            return;
        } else {
            list = Arrays.asList((Object[]) value);
            // special handling of container Object[]
        }
        writeArray(writer, list);
        return;
    }

    if (logger.isDebugEnabled())
        logger.debug("No suitable conversion found for {}. Will save it as string.", valueClass.getName());
    StaxUtilities.writeSimpleTextNode(writer, null, null, STRING_NODE, value.toString());
}

From source file:com.guodong.sun.guodong.uitls.CacheUtil.java

public static String getFormatSize(double size) {
    double kiloByte = size / 1024;
    if (kiloByte < 1) {
        //            return size + "Byte";
        return "0K";
    }/*from w  w  w.jav 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";
}