Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. public static String GetDecimal(double value){
  2.  
  3.         String result = String.valueOf(value);
  4.  
  5.         String Split[] = result.split("\\.");
  6.  
  7.         if ( (Split[1].length()) > 0 ) {
  8.  
  9.             String decimals = Split[1];
  10.  
  11.             //.x
  12.             if (decimals.length() < 2) {
  13.                 decimals = decimals + "0";
  14.             //.xx
  15.             }else {
  16.                 //.xxx
  17.                 if (decimals.length() > 2){
  18.                     //.99x
  19.                     if ( ( (Character.getNumericValue(decimals.charAt(0))) == 9 )  &&
  20.                             ( (Character.getNumericValue(decimals.charAt(1))) == 9 ) &&
  21.                             (decimals.charAt(2) > 5) ){
  22.                        
  23.                         decimals = "00";
  24.                         Split[0] = String.valueOf( (Integer.parseInt(Split[0]) ) + 1 );
  25.                        
  26.                     }
  27.                 }
  28.  
  29.             }
  30.  
  31.             return ( (Split[0]) + "." + (decimals.charAt(0)) + "" + (decimals.charAt(1)) );
  32.  
  33.         }else {
  34.  
  35.             return result;
  36.  
  37.         }
  38.  
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement