diff --git a/src/main/java/net/aufdemrand/denizen/objects/Element.java b/src/main/java/net/aufdemrand/denizen/objects/Element.java index e51f8ba431..2822faf1dc 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/Element.java +++ b/src/main/java/net/aufdemrand/denizen/objects/Element.java @@ -1,5 +1,6 @@ package net.aufdemrand.denizen.objects; +import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.Arrays; import java.util.regex.Matcher; @@ -150,6 +151,14 @@ public Element(String prefix, String string) { this.element = TagManager.cleanOutputFully(string); } + private BigDecimal getBD(String text) { + return new BigDecimal(text); + } + + public BigDecimal asBigDecimal() { + return getBD(element.replaceAll("%", "")); + } + public double asDouble() { return Double.valueOf(element.replaceAll("%", "")); } @@ -1483,7 +1492,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase())) dB.echoError("Element '" + element + "' is not a valid decimal number!"); return Element.NULL.getAttribute(attribute.fulfill(1)); } - return new Element(asDouble() + aH.getDoubleFrom(attribute.getContext(1))) + return new Element(asBigDecimal().add(getBD(attribute.getContext(1))).toString()) .getAttribute(attribute.fulfill(1)); } @@ -1500,7 +1509,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase())) dB.echoError("Element '" + element + "' is not a valid decimal number!"); return Element.NULL.getAttribute(attribute.fulfill(1)); } - return new Element(asDouble() / aH.getDoubleFrom(attribute.getContext(1))) + return new Element(asBigDecimal().divide(getBD(attribute.getContext(1))).toString()) .getAttribute(attribute.fulfill(1)); } @@ -1534,7 +1543,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase())) dB.echoError("Element '" + element + "' is not a valid decimal number!"); return Element.NULL.getAttribute(attribute.fulfill(1)); } - return new Element(asDouble() * aH.getDoubleFrom(attribute.getContext(1))) + return new Element(asBigDecimal().multiply(getBD(attribute.getContext(1))).toString()) .getAttribute(attribute.fulfill(1)); } @@ -1551,7 +1560,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase())) dB.echoError("Element '" + element + "' is not a valid decimal number!"); return Element.NULL.getAttribute(attribute.fulfill(1)); } - return new Element(asDouble() - aH.getDoubleFrom(attribute.getContext(1))) + return new Element(asBigDecimal().subtract(getBD(attribute.getContext(1))).toString()) .getAttribute(attribute.fulfill(1)); }