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:io.github.apfelcreme.Guilds.Command.Guild.Command.LevelCommand.java

/**
 * executes the command/*from   w  ww  . java2  s .  com*/
 *
 * @param commandSender the sender
 * @param strings       the command args
 */
public void execute(CommandSender commandSender, String[] strings) {
    Player sender = (Player) commandSender;
    if (sender.hasPermission("Guilds.level")) {
        if (strings.length > 1) {
            GuildLevel level = null;
            if (GuildsUtil.isNumeric(strings[1])) {
                level = plugin.getGuildsConfig().getLevelData(Integer.parseInt(strings[1]));
            } else {
                level = plugin.getGuildsConfig().getLevelData(strings[1]);
            }
            if (level != null) {
                plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.head")
                        .replace("{0}", level.getName()));

                if (plugin.getGuildsConfig().requireMoneyForUpgrade()) {
                    plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                            .getText("info.guild.level.cost").replace("{0}", Double.toString(level.getCost())));
                }
                if (plugin.getGuildsConfig().requireExpForUpgrade()) {
                    plugin.getChat().sendMessage(sender,
                            plugin.getGuildsConfig().getText("info.guild.level.expCost").replace("{0}",
                                    Integer.toString(level.getExpCost())));
                }
                if (plugin.getGuildsConfig().requireMaterialForUpgrade()) {
                    for (Map.Entry<Material, Integer> entry : level.getMaterialRequirements().entrySet()) {
                        plugin.getChat().sendMessage(sender,
                                plugin.getGuildsConfig().getText("info.guild.level.materialElement")
                                        .replace("{0}",
                                                WordUtils.capitalize(
                                                        entry.getKey().name().toLowerCase().replace("_", " ")))
                                        .replace("{1}", entry.getValue().toString()));
                    }
                }
                plugin.getChat().sendMessage(sender,
                        plugin.getGuildsConfig().getText("info.guild.level.head2"));
                plugin.getChat().sendMessage(sender,
                        plugin.getGuildsConfig().getText("info.guild.level.playerLimit").replace("{0}",
                                Integer.toString(level.getPlayerLimit())));
                if (plugin.getGuildsConfig().isEnchantmentBonusActivated()) {
                    plugin.getChat().sendMessage(sender,
                            plugin.getGuildsConfig().getText("info.guild.level.enchantmentCost").replace("{0}",
                                    Double.toString(level.getEnchantmentCost() * 100)));
                }
                if (plugin.getGuildsConfig().isDoubleCraftingBonusActivated()) {
                    plugin.getChat().sendMessage(sender,
                            plugin.getGuildsConfig().getText("info.guild.level.doubleCraftProbability")
                                    .replace("{0}", Double.toString(level.getDoubleCraftProbability() * 100)));
                }
                if (plugin.getGuildsConfig().isSpecialDropBonusActivated()) {
                    plugin.getChat().sendMessage(sender,
                            plugin.getGuildsConfig().getText("info.guild.level.specialDropChance")
                                    .replace("{0}", Double.toString(level.getSpecialDropChance() * 100)));
                }
                if (plugin.getGuildsConfig().isMoreFurnaceExpBonusActivated()) {
                    plugin.getChat().sendMessage(sender,
                            plugin.getGuildsConfig().getText("info.guild.level.furnaceExpGainRatio").replace(
                                    "{0}",
                                    Double.toString(Math.ceil((level.getFurnaceExpGainRatio() - 1) * 100))));
                }
            } else {
                plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.unknownLevel"));
            }
        } else {
            plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.wrongUsage.level"));
        }
    } else {
        plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noPermission"));
    }
}

From source file:com.nip.map.googlemap.DirectionsJSONParser.java

public List<List<HashMap<String, String>>> parse(JSONObject jObject) {

    List<List<HashMap<String, String>>> routes = new ArrayList<List<HashMap<String, String>>>();
    JSONArray jRoutes = null;//from w w  w.jav  a2 s . co m
    JSONArray jLegs = null;
    JSONArray jSteps = null;

    try {

        jRoutes = jObject.getJSONArray("routes");

        /** Traversing all routes */
        for (int i = 0; i < jRoutes.length(); i++) {
            jLegs = ((JSONObject) jRoutes.get(i)).getJSONArray("legs");
            List path = new ArrayList<HashMap<String, String>>();

            /** Traversing all legs */
            for (int j = 0; j < jLegs.length(); j++) {
                jSteps = ((JSONObject) jLegs.get(j)).getJSONArray("steps");

                /** Traversing all steps */
                for (int k = 0; k < jSteps.length(); k++) {
                    String polyline = "";
                    polyline = (String) ((JSONObject) ((JSONObject) jSteps.get(k)).get("polyline"))
                            .get("points");
                    List<LatLng> list = decodePoly(polyline);

                    /** Traversing all points */
                    for (int l = 0; l < list.size(); l++) {
                        HashMap<String, String> hm = new HashMap<String, String>();
                        hm.put("lat", Double.toString(((LatLng) list.get(l)).latitude));
                        hm.put("lng", Double.toString(((LatLng) list.get(l)).longitude));
                        path.add(hm);
                    }
                }
                routes.add(path);
            }
        }

    } catch (JSONException e) {
        e.printStackTrace();
    } catch (Exception e) {
    }

    return routes;
}

From source file:TemperatureConverter.java

/**
 * Performs conversion when one of the text fields changes.
 * /*from   ww  w  .  j ava  2s .  com*/
 * @param text
 *            the event source
 */
public void valueChanged(Text text) {
    if (!text.isFocusControl())
        return;

    if (text == fahrenheitValue) {
        try {
            double fValue = Double.parseDouble(text.getText());
            double cValue = (fValue - 32) / 1.8;
            celsiusValue.setText(Double.toString(cValue));
            System.out.println("F -> C: " + cValue);
            messageLabel.setText("Conversion performed successfully.");
        } catch (NumberFormatException e) {
            celsiusValue.setText("");
            messageLabel.setText("Invalid number format: " + text.getText());
        }
    } else {
        try {
            double cValue = Double.parseDouble(text.getText());
            double fValue = cValue * 1.8 + 32;
            fahrenheitValue.setText(Double.toString(fValue));
            System.out.println("C -> F: " + fValue);
            messageLabel.setText("Conversion performed successfully.");
        } catch (NumberFormatException e) {
            fahrenheitValue.setText("");
            messageLabel.setText("Invalid number format: " + text.getText());
        }
    }
}

From source file:dk.dma.ais.track.resource.MetricsResource.java

@GET
@Path("/flow/{meter}")
public String flow(@PathParam("meter") String meter,
        @DefaultValue("0.0") @QueryParam("expected") Double expexted) {
    Meter m = metrics.getMeters().get(meter);
    double rate = m.getFiveMinuteRate();
    HashMap<String, String> map = new HashMap<>();
    map.put("status", rate >= expexted ? "ok" : "error");
    map.put("rate", Double.toString(rate));
    map.put("expexted", Double.toString(expexted));
    try {/*  w  ww .  j  a  v  a  2  s.c  o  m*/
        return mapper.writeValueAsString(map);
    } catch (JsonProcessingException e) {
        LOG.error("Failed to generate metrics", e);
        throw new InternalServerErrorException();
    }
}

From source file:org.csware.ee.utils.Tools.java

public static double subtract(double v1, double v2)

{

    BigDecimal b1 = new BigDecimal(Double.toString(v1));

    BigDecimal b2 = new BigDecimal(Double.toString(v2));

    return b1.subtract(b2).doubleValue();

}

From source file:org.glom.web.server.Utils.java

/** Build the URL for the service that will return the binary data for an image.
 * /*from   ww w.j a  v a2 s.  com*/
 * @param primaryKeyValue
 * @param field
 * @return
 */
public static String buildImageDataUrl(final TypedDataItem primaryKeyValue, final String documentID,
        final String tableName, final LayoutItemField field) {
    final URIBuilder uriBuilder = buildImageDataUrlStart(documentID, tableName);

    //TODO: Handle other types:
    if (primaryKeyValue != null) {
        uriBuilder.setParameter("value", Double.toString(primaryKeyValue.getNumber()));
    }

    uriBuilder.setParameter("field", field.getName());
    return uriBuilder.toString();
}

From source file:br.unesp.rc.desafio.utils.Spreadsheet.java

public static ArrayList<String> ReadXlsSpreadsheet(File spreadsheet) {

    /*//from ww w  . java 2  s  .  c om
    Constructing File
    */
    ArrayList values = new ArrayList<String>();
    FileInputStream inputStr = null;
    try {
        inputStr = new FileInputStream(spreadsheet);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex);
    }

    Workbook currentSpreadsheetFile = null;

    try {
        HSSFRow row;
        currentSpreadsheetFile = new HSSFWorkbook(inputStr);
    } catch (IOException ex) {
        Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex);
    }

    Sheet sheet = currentSpreadsheetFile.getSheetAt(0);
    Iterator<Row> rowItr = sheet.rowIterator();

    while (rowItr.hasNext()) {
        row = (HSSFRow) rowItr.next();
        Iterator<Cell> cellIterator = row.cellIterator();
        while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();
            String cellValue = "";
            switch (cell.getCellTypeEnum()) {
            default:
                // cellValue = cell.getCellFormula();
                cellValue = Double.toString(cell.getNumericCellValue());
                cell.setCellType(CellType.STRING);
                cell.setCellValue(cellValue);
                break;
            case NUMERIC:
                cellValue = Double.toString(cell.getNumericCellValue());
                cell.setCellType(CellType.STRING);
                cell.setCellValue(cellValue);
            case BLANK:
                break;
            case STRING:
                break;
            }
            if (!cell.getStringCellValue().isEmpty()) {
                values.add(cell.getStringCellValue());
                values.add(",");
                // System.out.println("HOLD IT");
            } else {
                values.add("0");
                values.add(",");
                // System.out.println("OBJECTION!!");
            }
            //System.out.print(cell.getStringCellValue() + " \t\t " );
        }
        //System.out.println();
        values.add(";");

    }

    try {
        inputStr.close();
    } catch (IOException ex) {
        Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex);
    }
    //System.out.println(values.get(0));
    return values;
}

From source file:com.ns.retailmgr.connector.gmaps.GMapConnectorTest.java

@Test
public void test_getLngLatByAddress_Success() {
    GeoCodeLocInfo codingResponse = testGeoCodingResponse();
    when(restTemplate.getForObject(anyString(), eq(GeoCodeLocInfo.class))).thenReturn(codingResponse);
    Map<String, String> map = gmapConnector.getLngLatByAddress("TestShop");
    assertEquals(map.get("lat"), Double.toString(12.8124));
    assertEquals(map.get("lng"), Double.toString(177.69));
}

From source file:com.google.blockly.model.FieldAngle.java

@Override
public String getSerializedValue() {
    if (mAngle % 1 == 0.0) {
        // Don't print the decimal for integer values.
        return FieldNumber.INTEGER_DECIMAL_FORMAT.format(mAngle);
    } else {//  w  w  w.j  a v a 2  s  .c om
        return Double.toString(mAngle);
    }
}

From source file:springfox.bean.validators.plugins.MinMaxAnnotationPlugin.java

private AllowableValues createAllowableValuesFromMinMaxForNumbers(Optional<Min> min, Optional<Max> max) {
    AllowableRangeValues myvalues = null;

    if (min.isPresent() && max.isPresent()) {
        LOG.debug("@Min+@Max detected: adding AllowableRangeValues to field ");
        myvalues = new AllowableRangeValues(Double.toString(min.get().value()),
                Double.toString(max.get().value()));

    } else if (min.isPresent()) {
        LOG.debug("@Min detected: adding AllowableRangeValues to field ");
        // use Max value until "infinity" works
        myvalues = new AllowableRangeValues(Double.toString(min.get().value()),
                Double.toString(Double.MAX_VALUE));

    } else if (max.isPresent()) {
        // use Min value until "infinity" works
        LOG.debug("@Max detected: adding AllowableRangeValues to field ");
        myvalues = new AllowableRangeValues(Double.toString(Double.MIN_VALUE),
                Double.toString(max.get().value()));

    }/*from   w  ww .java2s. co m*/
    return myvalues;
}