Package org.kissweb

Class NumberUtils

java.lang.Object
org.kissweb.NumberUtils

public class NumberUtils extends Object
Author: Blake McBride Date: 10/24/20
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    doubleEqual(double d1, double d2, double maxdiff)
    Correctly compare two doubles.
    static boolean
    Is string a valid number?
    static void
    main(String[] args)
     
    static double
    Parse a String into a double.
    static int
    Parse a String into an int.
    static long
    Parse a String into a long.
    static double
    round(double n, int p)
    Round a number to the nearest p decimal places.
    static double
    roundDown(double n, int p)
    Round a number down to the nearest p decimal places.
    static double
    roundUp(double n, int p)
    Round a number up to the nearest p decimal places.
    static double
    trunk(double v)
    Truncate the decimal part of a number.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NumberUtils

      public NumberUtils()
  • Method Details

    • doubleEqual

      public static boolean doubleEqual(double d1, double d2, double maxdiff)
      Correctly compare two doubles.
      Parameters:
      d1 -
      d2 -
      maxdiff -
      Returns:
      true if the two doubles are different by less than maxdiff
    • round

      public static double round(double n, int p)
      Round a number to the nearest p decimal places.
      Parameters:
      n - the number to be rounded
      p - the number of decimal places
      Returns:
      the rounded number
    • roundUp

      public static double roundUp(double n, int p)
      Round a number up to the nearest p decimal places.
      Parameters:
      n - the number to be rounded
      p - the number of decimal places
      Returns:
      the rounded number
    • roundDown

      public static double roundDown(double n, int p)
      Round a number down to the nearest p decimal places.
      Parameters:
      n - the number to be rounded
      p - the number of decimal places
      Returns:
      the rounded number
    • trunk

      public static double trunk(double v)
      Truncate the decimal part of a number.
      Parameters:
      v -
      Returns:
    • parseDouble

      public static double parseDouble(String s)
      Parse a String into a double.
      Parameters:
      s -
      Returns:
    • parseLong

      public static long parseLong(String s)
      Parse a String into a long.
      Parameters:
      s -
      Returns:
    • isValidNumber

      public static boolean isValidNumber(String s)
      Is string a valid number?
      Parameters:
      s -
      Returns:
    • parseInt

      public static int parseInt(String s)
      Parse a String into an int.
      Parameters:
      s -
      Returns:
    • main

      public static void main(String[] args)