Advertisement
JeffGrigg

Double.toString for Infinity

Dec 3rd, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.47 KB | None | 0 0
  1.     public static String toString(final double value) {
  2.         if (Double.isInfinite(value)) {
  3.             if (value > 0) {
  4.                 return "\u221E";
  5.             } else {
  6.                 return "-\u221E";
  7.             }
  8.         } else if (Double.isNaN(value)) {
  9.             return "\uFFFD";    // Unicode "Replacement Character", a question mark in a black diamond, rougly meaning "unknown" (character)
  10.         } else {
  11.             return "" + value;
  12.         }
  13.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement