Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest you test it. It is a fairly expensive operation if you need to do this many, many times but can be less expensive than Double.toString() or Integer.toString() if you used those to create the data in the first place.</p> <p>I also suggest you only use <code>double</code> unless you know using a <code>float</code> could never ever cause a rounding issue. ;)</p> <p>It is about as expensive as creating objects, like String or adding an entry to a HashMap. Unless you plan to avoid do this as well, I wouldn't worry about it. </p> <p>EDIT: Similar to @Stackers' benchmark I would run the test longer and use nanoTime()</p> <pre><code>int runs = 10000000; String val = "" + Math.PI; long start = System.nanoTime(); for (int i = 0; i &lt; runs; i++) Float.parseFloat(val); long time = (System.nanoTime() - start) / runs; System.out.println("Average Float.parseFloat() time was " + time + " ns."); long start2 = System.nanoTime(); for (int i = 0; i &lt; runs; i++) Double.parseDouble(val); long time2 = (System.nanoTime() - start2) / runs; System.out.println("Average Double.parseDouble() time was " + time2 + " ns."); </code></pre> <p>prints</p> <pre><code>Average Float.parseFloat() time was 474 ns. Average Double.parseDouble() time was 431 ns. </code></pre> <p>BTW: I have function which reads doubles from a direct ByteBuffer which takes 80 ns. It is faster because it doesn't need a String and it doesn't create any objects. However, it is by no means trivial to do this and you have to design your core system to avoid any object creation. ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload