Java Double Number Truncate truncate(double x, double gran)

Here you can find the source of truncate(double x, double gran)

Description

truncate

License

Apache License

Declaration

public static double truncate(double x, double gran) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static double truncate(double x, double gran) {
        return Math.round(x / gran) * gran;
    }/*from   ww w.ja v a  2s  .  co  m*/

    public static int round(double number) {
        return (int) (Math.round(number) + 0.5);
    }

    public static int round(float number) {
        return (int) (Math.round(number) + 0.5);
    }
}

Related

  1. truncate(double value, double precision)
  2. truncate(double value, int precision)
  3. truncate(double value, int truncation)
  4. truncate(double x)
  5. truncate(double x)
  6. truncate(double[] arr, int m)
  7. truncate(final double value, final double min, final double max)
  8. truncate(final double value, final double precision)
  9. truncate2decimals(double x)