Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed precision of doubles not being correct causing incorrect mathem…
…atical operations (#1293)
- Loading branch information
1 parent
92da107
commit 1f589d5
Showing
3 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/bgsoftware/superiorskyblock/core/Precision.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bgsoftware.superiorskyblock.core; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
|
||
public class Precision { | ||
|
||
private Precision() { | ||
|
||
} | ||
|
||
public static double round(double value, int places) { | ||
if (places < 0) throw new IllegalArgumentException(); | ||
|
||
BigDecimal bd = new BigDecimal(Double.toString(value)); | ||
bd = bd.setScale(places, RoundingMode.HALF_DOWN); | ||
return bd.doubleValue(); | ||
} | ||
|
||
} |
This file contains 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