Skip to content

Instantly share code, notes, and snippets.

@BukhariH
Created August 17, 2018 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BukhariH/f52a9c4210f881310432926d834dc68a to your computer and use it in GitHub Desktop.
Save BukhariH/f52a9c4210f881310432926d834dc68a to your computer and use it in GitHub Desktop.
Checks if a BigDecimal is with in a tolerance value
private static boolean isWithinTolerance(BigDecimal amount, BigDecimal tolerance) {
return (amount.compareTo(tolerance.negate()) > 0 && amount.compareTo(tolerance) < 0)
|| amount.abs().compareTo(tolerance) == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment