Last active
December 8, 2015 10:52
-
-
Save vaibhav-jani/fd4df4de44a01378f338 to your computer and use it in GitHub Desktop.
Round the decimal with coefficient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // amount = 1.2244 with round 0.003 will be 1.23, with round 0.005 will be 1.22, with round 0.03 will be 1.3 | |
| public static String taxFormat(double taxAmount, double round) { | |
| try { | |
| String extensionRemoved = String.valueOf(round).split("\\.")[1]; | |
| int sigCount = extensionRemoved.length() - 1; | |
| double addjust = 1.0; | |
| for (int i = 0; i < sigCount; i++) { | |
| addjust = addjust/10.0; | |
| } | |
| double coefficient = addjust - round; | |
| taxAmount = taxAmount + coefficient; | |
| BigDecimal bigDecimal = new BigDecimal(taxAmount); | |
| bigDecimal = bigDecimal.setScale(sigCount, BigDecimal.ROUND_DOWN); | |
| //bigDecimal.doubleValue(); | |
| String value = String.valueOf(bigDecimal); | |
| return value; | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| return String.valueOf(taxAmount); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment