Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html#nextAfter%28float,%20double%29" rel="nofollow">nextAfter(double start, double direction)</a>:</p> <pre><code>import java.math.*; public class a { public static void printNeighbours(BigDecimal start) { double result1 = start.doubleValue(); double result2; BigDecimal r1 = new BigDecimal(result1); int com = start.compareTo(r1); if(com != 0) result2 = Math.nextAfter(result1, com * Double.MAX_VALUE); else { result2 = Math.nextAfter(result1, Double.MAX_VALUE); result1 = Math.nextAfter(result1, -Double.MAX_VALUE); r1 = new BigDecimal(result1); } BigDecimal r2 = new BigDecimal(result2); System.out.println("starting:\t"+start); if(com&lt;0) { System.out.println("smaller:\t" + r2); System.out.println("bigger:\t\t"+r1); } else { System.out.println("smaller:\t" + r1); System.out.println("bigger:\t\t"+r2); } System.out.println(); } public static void main(String[] args) { printNeighbours(new BigDecimal("0.25")); printNeighbours(new BigDecimal("0.1")); printNeighbours(new BigDecimal("0.7")); } } </code></pre> <p>Printout:</p> <pre><code>starting: 0.25 smaller: 0.2499999999999999722444243843710864894092082977294921875 bigger: 0.250000000000000055511151231257827021181583404541015625 starting: 0.1 smaller: 0.09999999999999999167332731531132594682276248931884765625 bigger: 0.1000000000000000055511151231257827021181583404541015625 starting: 0.7 smaller: 0.6999999999999999555910790149937383830547332763671875 bigger: 0.70000000000000006661338147750939242541790008544921875 </code></pre>
    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