Skip to content

Commit

Permalink
add element.round_down and .round_up
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 30, 2013
1 parent 6bb762f commit 16c8333
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -241,11 +241,41 @@ public String getAttribute(Attribute attribute) {
|| attribute.startsWith("as_entity"))
return dEntity.valueOf(element).getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <el@element.round_up>
// @returns Element(Number)
// @description
// Rounds a decimal upward.
// -->
if (attribute.startsWith("round_up"))
try {
return new Element((int)Math.ceil(Double.valueOf(element)))
.getAttribute(attribute.fulfill(1)); }
catch (NumberFormatException e) {
dB.echoError("'" + element + "' is not a valid Integer.");
return new Element("null").getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <el@element.round_down>
// @returns Element(Number)
// @description
// Rounds a decimal downward.
// -->
if (attribute.startsWith("round_down"))
try {
return new Element((int)Math.floor(Double.valueOf(element)))
.getAttribute(attribute.fulfill(1)); }
catch (NumberFormatException e) {
dB.echoError("'" + element + "' is not a valid Integer.");
return new Element("null").getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <el@element.as_int>
// @returns Element(Number)
// @description
// Returns the element as a number without a decimal. Rounds up double values.
// Returns the element as a number without a decimal. Rounds double values.
// -->
if (attribute.startsWith("asint")
|| attribute.startsWith("as_int"))
Expand Down

0 comments on commit 16c8333

Please sign in to comment.