Java Double Number Truncate trunc(double x)

Here you can find the source of trunc(double x)

Description

Return the integer portion of a double as a double.

License

Open Source License

Parameter

Parameter Description
x The double whose integer portion is to be found.

Return

The integer portion of x.

Example: trunc( 30.12345D ) is 30.0D .

Declaration


public static double trunc(double x) 

Method Source Code

//package com.java2s;
/*   Please see the license information in the header below. */

public class Main {
    /** Return the integer portion of a double as a double.
     */* w  w  w .jav a 2 s.  c  o m*/
     *   @param   x   The double whose integer portion is to be found.
     *
     *   @return      The integer portion of x.
     *
     *   <p>
     *   Example:   trunc( 30.12345D ) is 30.0D .
     *   </p>
     */

    public static double trunc(double x) {
        long lx = (long) x;
        return (double) lx;
    }
}

Related

  1. trunc(double value)
  2. trunc(double value, double threshold)
  3. trunc(double value, int dp)
  4. trunc(double value, int len)
  5. trunc(double x)
  6. trunc(double x, double y)
  7. trunc4(Double number)
  8. truncate(double d)
  9. truncate(double fullVal, int digits)