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:de.topobyte.livecg.core.painting.backend.svg.SvgPainter.java

@Override
public void drawRect(double x, double y, double width, double height) {
    Element rectangle = doc.createElementNS(svgNS, "rect");
    rectangle.setAttributeNS(null, "x", Double.toString(x));
    rectangle.setAttributeNS(null, "y", Double.toString(y));
    rectangle.setAttributeNS(null, "width", Double.toString(width));
    rectangle.setAttributeNS(null, "height", Double.toString(height));
    addStrokeAttributes(rectangle);//from   w  ww .  ja  v a  2 s .  co  m
    rectangle.setAttributeNS(null, "fill", "none");

    append(rectangle);
}

From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java

/**
 * Produce a string from a double. The string "null" will be returned if the
 * number is not finite.//from w ww.  j  ava 2 s .  c  om
 *
 * @param d A double.
 * @return A String.
 */
public static String doubleToString(double d) {
    if (Double.isInfinite(d) || Double.isNaN(d)) {
        return "null";
    }

    // Shave off trailing zeros and decimal point, if possible.

    String s = Double.toString(d);
    if (s.indexOf('.') > 0 && s.indexOf('e') < 0 && s.indexOf('E') < 0) {
        while (s.endsWith("0")) {
            s = s.substring(0, s.length() - 1);
        }
        if (s.endsWith(".")) {
            s = s.substring(0, s.length() - 1);
        }
    }
    return s;
}

From source file:no.ntnu.idi.socialhitchhiking.map.RouteProvider.java

/**
 * Creates a url that should be used to retrieve a route from google maps.
 * /*  w  w w  .ja  va 2 s.  c  o m*/
 * @param fromLat
 * @param fromLon
 * @param toLat
 * @param toLon
 * @return
 */
private static String getUrl(double fromLat, double fromLon, double toLat, double toLon) {// connect to map web service
    StringBuffer urlString = new StringBuffer();
    urlString.append("http://maps.googleapis.com/maps/api/directions/xml?");
    urlString.append("origin=");// from
    urlString.append(Double.toString(fromLat));
    urlString.append(",");
    urlString.append(Double.toString(fromLon));
    urlString.append("&destination=");// to
    urlString.append(Double.toString(toLat));
    urlString.append(",");
    urlString.append(Double.toString(toLon));
    urlString.append("&sensor=false");
    return urlString.toString();
}

From source file:byps.BBufferJson.java

public void putDouble(double v) {
    putJsonValueAscii(null, Double.toString(v), STRING_WITHOUT_QUOTE);
}

From source file:io.github.apfelcreme.Guilds.Command.Guild.Command.UpgradeCommand.java

/**
 * executes the command/*  ww w.j  a v a 2s  . com*/
 *
 * @param commandSender the sender
 * @param strings       the command args
 */
public void execute(CommandSender commandSender, String[] strings) {
    Player sender = (Player) commandSender;
    if ((plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE
            && sender.getGameMode() != GameMode.CREATIVE)
            || sender.hasPermission("Guilds.upgradeGuildCreative")) {
        if (sender.hasPermission("Guilds.upgradeGuild")) {
            Guild guild = plugin.getGuildManager().getGuild(sender);
            if (guild != null) {
                if (guild.getMember(sender.getUniqueId()).getRank().canUpgrade()) {
                    if (plugin.getGuildManager().hasNextLevel(guild)) {
                        if (plugin.getGuildManager().canBeUpgraded(guild, sender)) {
                            plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                                    .getColoredText("info.guild.upgrade.ready", guild.getColor())
                                    .replace("{0}", plugin.getGuildManager().getNextLevel(guild).getName()));
                        } else {
                            plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                                    .getColoredText("info.guild.upgrade.requirementsMissing", guild.getColor())
                                    .replace("{0}", plugin.getGuildManager().getNextLevel(guild).getName()));
                        }
                        if (plugin.getGuildsConfig().requireMoneyForUpgrade()) {
                            if (guild.getBalance() >= plugin.getGuildManager().getNextLevel(guild).getCost()) {
                                plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                                        .getColoredText("info.guild.upgrade.enoughMoney", guild.getColor())
                                        .replace("{0}", Double.toString(guild.getBalance()))
                                        .replace("{1}", Double.toString(
                                                plugin.getGuildManager().getNextLevel(guild).getCost())));
                            } else {
                                plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                                        .getColoredText("info.guild.upgrade.notEnoughMoney", guild.getColor())
                                        .replace("{0}", Double.toString(guild.getBalance()))
                                        .replace("{1}", Double.toString(
                                                plugin.getGuildManager().getNextLevel(guild).getCost())));
                            }
                        }
                        if (plugin.getGuildsConfig().requireExpForUpgrade()) {
                            if (guild.getExp() >= plugin.getGuildManager().getNextLevel(guild).getExpCost()) {
                                plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                                        .getColoredText("info.guild.upgrade.enoughExp", guild.getColor())
                                        .replace("{0}", Integer.toString(guild.getExp()))
                                        .replace("{1}", Integer.toString(
                                                plugin.getGuildManager().getNextLevel(guild).getExpCost())));
                            } else {
                                plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                                        .getColoredText("info.guild.upgrade.notEnoughExp", guild.getColor())
                                        .replace("{0}", Integer.toString(guild.getExp()))
                                        .replace("{1}", Integer.toString(
                                                plugin.getGuildManager().getNextLevel(guild).getExpCost())));
                            }
                        }
                        if (plugin.getGuildsConfig().requireMaterialForUpgrade()) {
                            for (Map.Entry<Material, Integer> entry : plugin.getGuildManager()
                                    .getNextLevel(guild).getMaterialRequirements().entrySet()) {
                                if (GuildsUtil.countItems(sender.getInventory(), entry.getKey(), false) >= entry
                                        .getValue()) {
                                    plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                                            .getColoredText("info.guild.upgrade.enoughMaterialElement",
                                                    guild.getColor())
                                            .replace("{0}",
                                                    WordUtils.capitalize(entry.getKey().name().toLowerCase()
                                                            .replace("_", " ")))
                                            .replace("{1}",
                                                    Integer.toString(GuildsUtil.countItems(
                                                            sender.getInventory(), entry.getKey(), false)))
                                            .replace("{2}", plugin.getGuildManager().getNextLevel(guild)
                                                    .getMaterialRequirements().get(entry.getKey()).toString()));
                                } else {
                                    plugin.getChat().sendMessage(sender, plugin.getGuildsConfig()
                                            .getColoredText("info.guild.upgrade.notEnoughMaterialElement",
                                                    guild.getColor())
                                            .replace("{0}",
                                                    WordUtils.capitalize(entry.getKey().name().toLowerCase()
                                                            .replace("_", " ")))
                                            .replace("{1}",
                                                    Integer.toString(GuildsUtil.countItems(
                                                            sender.getInventory(), entry.getKey(), false)))
                                            .replace("{2}", plugin.getGuildManager().getNextLevel(guild)
                                                    .getMaterialRequirements().get(entry.getKey()).toString()));

                                }
                            }
                        }
                        if (plugin.getGuildManager().canBeUpgraded(guild, sender)) {
                            // guild is ready to be upgraded
                            plugin.getRequestController().addRequest(new UpgradeRequest(plugin, sender, guild));
                        }
                    } else {
                        plugin.getChat().sendMessage(sender,
                                plugin.getGuildsConfig().getText("error.guildFullyUpgraded"));
                    }
                } else {
                    plugin.getChat().sendMessage(sender,
                            plugin.getGuildsConfig().getText("error.rank.noPermission").replace("{0}",
                                    plugin.getGuildsConfig().getText("info.guild.rank.info.upgrade")));
                }
            } else {
                plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noCurrentGuild"));
            }
        } else {
            plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noPermission"));
        }
    } else {
        plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noSurvival"));
    }
}

From source file:ee.ria.xroad.common.RequestTest.java

/**
 * Test to ensure bodymass index test RPC request (with version) creation is correct.
 * @throws IOException if request template file could not be read
 *///from   w  ww.j a  va 2 s  .c o  m
@Test
public void shouldCreateBodyMassIndexRpcRequestWithVersion() throws IOException {
    // Given
    ClientId client = ClientId.create("EE", "riigiasutus", "consumer", "subClient");

    ServiceId service = ServiceId.create("EE", "riigiasutus", "producer", "subService", "bodyMassIndex", "v1");

    String id = "1234567890";

    List<RequestTag> content = Arrays.asList(new RequestTag("height", Integer.toString(180)),
            new RequestTag("weight", Double.toString(80.1)));

    String template = FileUtils
            .readFileToString(new File(TEMPLATES_DIR + File.separator + "v5DoclitRequest.st"));

    Request request = new Request(template, client, service, id, content);

    // When
    String xmlFromRequest = request.toXml();
    System.out.println("XML from request: " + xmlFromRequest);

    // Then
    String expectedRequest = FileUtils
            .readFileToString(new File("src/test/resources/v5DoclitWithVersion.request"));
    assertEquals(expectedRequest, xmlFromRequest);
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.ValueConverter.java

private String singleObjectToString(Object value) {
    if (value == null) {
        return "";
    }//from w ww.j  a  v a  2  s .  c om
    if (value instanceof String) {
        return escapeStringValue((String) value);
    }
    if (value instanceof Boolean) {
        return ((Boolean) value).toString();
    }
    if (value instanceof Integer || value instanceof Long) {
        return Long.toString(((Number) value).longValue());
    }
    if (value instanceof Double) {
        return Double.toString(((Double) value).doubleValue());
    }
    if (value instanceof BigDecimal) {
        return Double.toString(((BigDecimal) value).doubleValue());
    }
    if (value instanceof Date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime((Date) value);
        return ISO8601.format(calendar);
    }
    if (value instanceof Calendar) {
        return ISO8601.format((Calendar) value);
    }
    throw new IllegalArgumentException("Type not supported: " + value.getClass().getName());
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java

String processVariableValue(ByteBuf cb) throws PEException {
    String value = StringUtils.EMPTY;

    valueType = MyItemResultCode.fromByte(cb.readByte());
    valueCharSet = cb.readInt();//w  ww .  ja v  a  2 s.c o  m
    valueLen = cb.readInt();
    valueBytes = Unpooled.buffer(cb.readableBytes()).order(ByteOrder.LITTLE_ENDIAN);
    valueBytes.writeBytes(cb);

    switch (valueType) {
    case DECIMAL_RESULT:
        value = processDecimalValue(valueBytes, valueLen);
        break;
    case INT_RESULT:
        value = processIntValue(valueBytes, valueLen);
        break;
    case REAL_RESULT:
        value = Double.toString(valueBytes.readDouble());
        break;
    case STRING_RESULT:
        value = "'" + StringUtils.replace(
                MysqlAPIUtils.readBytesAsString(valueBytes, valueLen, CharsetUtil.UTF_8), "'", "''") + "'";
        break;
    case ROW_RESULT:
    default:
        throw new PEException(
                "Unsupported variable type '" + valueType + "' for variable '" + variableName + "'");
    }
    return value;
}

From source file:com.rvce.rvce8thmile.driver.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    gps = new GPSTracker(getApplicationContext());
    busno = (EditText) findViewById(R.id.editText);
    license = (EditText) findViewById(R.id.editText2);
    mybtn = (Button) findViewById(R.id.mybtn);

    mybtn.setOnClickListener(new View.OnClickListener() {
        @Override//w w  w.  j ava  2  s .co m
        public void onClick(View v) {

            final SharedPreferences prefs = getSharedPreferences(MainActivity.class.getSimpleName(),
                    Context.MODE_PRIVATE);

            SharedPreferences.Editor editor = prefs.edit();
            if (!busno.getText().equals("")) {
                if (prefs.contains("busno"))
                    editor.remove("busno");
                editor.putString("busno", busno.getText().toString());
            }
            if (!license.getText().equals("")) {
                if (prefs.contains("license"))
                    editor.remove("license");
                editor.putString("license", license.getText().toString());
            }

            editor.apply();

            // check if GPS enabled
            if (gps.canGetLocation()) {
                latitude = gps.getLatitude();
                longitude = gps.getLongitude();

            } else {
                // can't get location
                // GPS or Network is not enabled
                // Ask user to enable GPS/network in settings
                gps.showSettingsAlert();
            }

            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    HttpClient httpClient = new DefaultHttpClient();
                    //HttpPost httpPost=new HttpPost("https://rotaractrvce.com/bidn/updateuser.php");
                    HttpPost httpPost = new HttpPost("http://rotaractrvce.com/bidn/updatebus.php");
                    BasicResponseHandler responseHandler = new BasicResponseHandler();
                    List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(4);
                    nameValuePair.add(new BasicNameValuePair("busno", busno.getText().toString()));
                    nameValuePair.add(new BasicNameValuePair("license", license.getText().toString()));
                    nameValuePair.add(new BasicNameValuePair("x", Double.toString(latitude)));
                    nameValuePair.add(new BasicNameValuePair("y", Double.toString(longitude)));
                    try {
                        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
                    } catch (UnsupportedEncodingException e) {
                        // log exception
                        e.printStackTrace();
                    }
                    try {
                        ans = httpClient.execute(httpPost, responseHandler);
                        //Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            t.start();
            try {
                t.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Toast.makeText(getApplicationContext(), latitude.toString() + " : " + longitude.toString(),
                    Toast.LENGTH_SHORT).show();

            startService(new Intent(MainActivity.this, TTSService.class));
        }
    });

}

From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNumActionsStatistics.java

public void writeSessionsOverTime(final String outputDir) throws IOException {
    FileWriter fw = new FileWriter(outputDir + "/" + this.getClass().getSimpleName() + "-sessionLengths.csv");
    BufferedWriter writer = new BufferedWriter(fw);

    writer.write("length");
    writer.newLine();//from  ww  w  .  java 2s.  c om
    for (double l : this.computeLengthVector()) {
        writer.write(Double.toString(l));
        writer.newLine();
    }

    writer.close();
    fw.close();
}