List of usage examples for java.lang Double toString
public static String toString(double d)
From source file:Main.java
/** * Build url for route calculation/* ww w .j a va 2s . c o m*/ * * @param fromLat start point latitude * @param fromLon start point longitude * @param toLat destination point latitude * @param toLon destination point longitude * @param context current context * @return route url for Google Maps service */ public static String getUrl(double fromLat, double fromLon, double toLat, double toLon, Context context) {// connect to map web service final StringBuilder urlString = new StringBuilder(); final String currentLanguage = context.getResources().getConfiguration().locale.getLanguage(); urlString.append("http://maps.googleapis.com/maps/api/directions/json?language="); urlString.append(currentLanguage); //current language 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("&ie=UTF8&mode=driving&sensor=true"); return urlString.toString(); }
From source file:Main.java
/** * Append text value node./*from w ww .j a v a 2s.co m*/ * * @param baseNode * the base node * @param tagName * the tag name * @param tagValue * the tag value * @return the element */ public static Element appendTextValueNode(Node baseNode, String tagName, double tagValue) { return appendTextValueNode(baseNode, tagName, Double.toString(tagValue)); }
From source file:Main.java
public static String getFormatSize(double size) { double kiloByte = size / 1024; if (kiloByte < 1) { return size + "Byte"; }/* w w w . j a v a 2s.c om*/ 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[] showLocation(Location location) { String[] currentLocation = new String[2]; if (location != null) { String lat = Double.toString(location.getLatitude()); String lng = Double.toString(location.getLongitude()); Log.v("LAT", "latitude:" + lat); Log.v("Longitude", "longitude:" + lng); currentLocation[0] = lat;/* www . ja v a 2 s . c o m*/ currentLocation[1] = lng; Log.v("GPS", currentLocation[0] + ":" + currentLocation[1]); } else { currentLocation[0] = "-1"; currentLocation[1] = "-1"; Log.v("LOC", "Location not available."); } return currentLocation; }
From source file:ctlogger.CTlogger.java
public static void main(String args[]) { /**/* w w w . jav a 2s .co m*/ * * Original code for command line parsing * (This has been replaced by code using Apache Commons CLI, see below) * String helpMsg = "CTlogger -x -r -z -g -k <skiplines> -f <flush_sec> -p <poll_sec> -n <nanVal> -i <leadingID> -s <SourceName> -H <HeaderLine> <logger.dat> <CTfolder>"; int dirArg = 0; while((dirArg<args.length) && args[dirArg].startsWith("-")) { // arg parsing if(args[dirArg].equals("-h")) { System.err.println(helpMsg); System.exit(0); } if(args[dirArg].equals("-x")) { debug = true; } if(args[dirArg].equals("-b")) { noBackwards = true; } if(args[dirArg].equals("-g")) { gzipmode = true; } // default false if(args[dirArg].equals("-a")) { appendMode = false; } // default true if(args[dirArg].equals("-z")) { zipmode = false; } // default true if(args[dirArg].equals("-N")) { newFileMode = true; } // default false if(args[dirArg].equals("-f")) { autoflush = Long.parseLong(args[++dirArg]); } if(args[dirArg].equals("-p")) { pollInterval = Long.parseLong(args[++dirArg]); } if(args[dirArg].equals("-k")) { skipLines = Long.parseLong(args[++dirArg]); } if(args[dirArg].equals("-r")) { repeatFetch = true; } if(args[dirArg].equals("-B")) { blockMode = true; } if(args[dirArg].equals("-t")) { storeTime = true; } if(args[dirArg].equals("-T")) { trimTime = Double.parseDouble(args[++dirArg]); } if(args[dirArg].equals("-n")) { nanVal = args[++dirArg]; } if(args[dirArg].equals("-i")) { leadingID = args[++dirArg]; } if(args[dirArg].equals("-s")) { SourceName = args[++dirArg]; } if(args[dirArg].equals("-H")) { HeaderLine = args[++dirArg]; } dirArg++; } if(args.length < (dirArg+2)) { System.err.println(helpMsg); System.exit(0); } loggerFileName = args[dirArg++]; // args[0]: logger.dat file CTrootfolder = args[dirArg++]; // args[1]: CT destination folder */ // // Parse command line arguments // // 1. Setup command line options // Options options = new Options(); // Boolean options (only the flag, no argument) options.addOption("h", "help", false, "Print this message"); options.addOption("x", "debug", false, "turn on debug output"); options.addOption("b", "nobackwards", false, "no backwards-going time allowed"); options.addOption("g", "gzipmode", false, "turn on gzip for extra compression"); options.addOption("a", "noappend", false, "turn off append mode (i.e., do not append to end of existing CT data)"); options.addOption("z", "nozip", false, "turn off zip mode (it is on by default)"); options.addOption("N", "newfilemode", false, "re-parse entire logger file every time it is checked"); options.addOption("r", "repeatFetch", false, "turn on repeat fetch (auto-fetch data loop)"); options.addOption("B", "blockMode", false, "turn on CloudTurbine writer block mode (multiple points per output data file, packed data)"); options.addOption("t", "storeTime", false, "store time string as a channel; time is the first data entry in each line; if this option is not specified, then the time channel is skipped/not saved to CloudTurbine"); // Options with an argument Option outputFolderOption = Option.builder("f").argName("autoflush").hasArg() .desc("flush interval (sec); default = \"" + autoflush + "\"").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("p").argName("pollInterval").hasArg().desc( "if repeatFetch option has been specified, recheck the logger data file at this polling interval (sec); default = \"" + pollInterval + "\"") .build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("k").argName("skipLines").hasArg().desc( "in logger file, the num lines to skip after the header line to get to the first line of data; default = \"" + skipLines + "\"") .build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("T").argName("trimTime").hasArg().desc( "trim (ring-buffer loop) time (sec) (trimTime=0 for indefinite); default = \"" + trimTime + "\"") .build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("n").argName("nanVal").hasArg() .desc("replace NAN with this; default = \"" + nanVal + "\"").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("i").argName("leadingID").hasArg() .desc("leading ID string (IWG1 compliant)").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("s").argName("sourceName").hasArg() .desc("CloudTurbine source name; default = \"" + SourceName + "\"").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("H").argName("HeaderLine").hasArg().desc( "optional CSV list of channel names; if not supplied, this is read from the first line in the logger file") .build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("l").argName("loggerfilename").hasArg() .desc("name of the logger data file; required argument").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("o").longOpt("outputfolder").argName("folder").hasArg() .desc("Location of output files (source is created under this folder); default = " + CTrootfolder) .build(); options.addOption(outputFolderOption); // // 2. Parse command line options // CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (org.apache.commons.cli.ParseException exp) { // oops, something went wrong System.err.println("Command line argument parsing failed: " + exp.getMessage()); return; } // // 3. Retrieve the command line values // if (line.hasOption("help")) { // Display help message and quit HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("CTlogger", options); return; } debug = line.hasOption("x"); noBackwards = line.hasOption("b"); gzipmode = line.hasOption("g"); appendMode = !line.hasOption("a"); zipmode = !line.hasOption("z"); newFileMode = line.hasOption("N"); repeatFetch = line.hasOption("r"); blockMode = line.hasOption("B"); storeTime = line.hasOption("t"); autoflush = Long.parseLong(line.getOptionValue("f", Long.toString(autoflush))); pollInterval = Long.parseLong(line.getOptionValue("p", Long.toString(pollInterval))); skipLines = Long.parseLong(line.getOptionValue("k", Long.toString(skipLines))); trimTime = Double.parseDouble(line.getOptionValue("T", Double.toString(trimTime))); nanVal = line.getOptionValue("n", nanVal); if (line.hasOption("i")) { leadingID = line.getOptionValue("i"); } SourceName = line.getOptionValue("s", SourceName); if (line.hasOption("H")) { HeaderLine = line.getOptionValue("H"); } if (line.hasOption("l")) { loggerFileName = line.getOptionValue("l"); } else { System.err.println("ERROR: you must supply the logger file name."); return; } CTrootfolder = line.getOptionValue("o", CTrootfolder); if (!debug) { System.err.println("CTlogger: " + loggerFileName + ", CTrootfolder: " + CTrootfolder + ", pollInterval: " + pollInterval); } else { System.err.println("debug = " + debug); System.err.println("noBackwards = " + noBackwards); System.err.println("gzipmode = " + gzipmode); System.err.println("appendMode = " + appendMode); System.err.println("zipmode = " + zipmode); System.err.println("newFileMode = " + newFileMode); System.err.println("repeatFetch = " + repeatFetch); System.err.println("blockMode = " + blockMode); System.err.println("storeTime = " + storeTime); System.err.println("autoflush = " + autoflush); System.err.println("pollInterval = " + pollInterval); System.err.println("skipLines = " + skipLines); System.err.println("trimTime = " + trimTime); System.err.println("nanVal = " + nanVal); System.err.println("leadingID = " + leadingID); System.err.println("SourceName = " + SourceName); System.err.println("HeaderLine = " + HeaderLine); System.err.println("loggerFileName = " + loggerFileName); System.err.println("CTrootfolder = " + CTrootfolder); } // // Run CTlogger // if (!repeatFetch) getData(true); // run once else { Timer timer = new Timer(); TimerTask fetchTask = new TimerTask() { @Override public void run() { if (newFileMode) getData(true); else if (getData(false)) { // pick up from old data if you can System.err.println("Failed to pick up from old data, refetch from start of file..."); boolean status = getData(true); System.err.println("refetch status: " + status); } if (debug) System.err.println("Waiting for data, pollInterval: " + pollInterval + " sec..."); }; }; // repeatFetch@autoflush interval, convert to msec if ((autoflush > 0) && (pollInterval > autoflush)) pollInterval = autoflush; timer.scheduleAtFixedRate(fetchTask, 0, pollInterval * 1000); } }
From source file:Main.java
public static double round(double v, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); }//from w ww.ja v a2 s . c o m BigDecimal b = new BigDecimal(Double.toString(v)); BigDecimal one = new BigDecimal("1"); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); }
From source file:Main.java
/** * Creates an attribute with content in the form of a double *///from www .ja v a2s . c om public static void setAttribute(Element element, String name, double value) { setAttribute(element, name, Double.toString(value)); }
From source file:WriteFile.java
private static void writeMovie(Product m, PrintWriter out) { String line = m.title;//from w w w. jav a 2 s . c om line += "\t" + Integer.toString(m.year); line += "\t" + Double.toString(m.price); out.println(line); }
From source file:br.on.daed.services.pdf.DadosMagneticos.java
public static byte[] gerarPDF(String ano, String tipo) throws IOException, InterruptedException, UnsupportedOperationException { File tmpFolder;/*from w ww . j av a 2s .c o m*/ String folderName; Double anoDouble = Double.parseDouble(ano); List<String> dados = Arrays.asList(TIPO_DADOS_MAGNETICOS); byte[] ret = null; if (anoDouble >= ANO_MAGNETICO[0] && anoDouble < ANO_MAGNETICO[1] && dados.contains(tipo)) { do { folderName = "/tmp/dislin" + Double.toString(System.currentTimeMillis() * Math.random()); tmpFolder = new File(folderName); } while (tmpFolder.exists()); tmpFolder.mkdir(); ProcessBuilder processBuilder = new ProcessBuilder("/opt/declinacao-magnetica/./gerar", ano, tipo); processBuilder.directory(tmpFolder); processBuilder.environment().put("LD_LIBRARY_PATH", "/usr/local/dislin"); Process proc = processBuilder.start(); proc.waitFor(); ProcessHelper.outputProcess(proc); File arquivoServido = new File(folderName + "/dislin.pdf"); FileInputStream fis = new FileInputStream(arquivoServido); ret = IOUtils.toByteArray(fis); processBuilder = new ProcessBuilder("rm", "-r", folderName); tmpFolder = new File("/"); processBuilder.directory(tmpFolder); Process delete = processBuilder.start(); delete.waitFor(); } else { throw new UnsupportedOperationException("Entrada invlida"); } return ret; }
From source file:Main.java
/** * Round the given value to the specified number of decimal places. The * value is rounded using the given method which is any method defined in * {@link BigDecimal}.//w ww. ja va 2 s. c om * * @param x the value to round. * @param scale the number of digits to the right of the decimal point. * @param roundingMethod the rounding method as defined in * {@link BigDecimal}. * @return the rounded value. * @since 1.1 */ public static double round(double x, int scale, int roundingMethod) { try { return (new BigDecimal(Double.toString(x)).setScale(scale, roundingMethod)).doubleValue(); } catch (NumberFormatException ex) { if (Double.isInfinite(x)) { return x; } else { return Double.NaN; } } }