Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function round(temp.number) {
- // Divide the number into whole and decimals.
- temp.tokens = temp.number.tokenize(".");
- // This means they've sent a whole number. Return the whole number
- if (temp.tokens.size() == 1) { return temp.number; }
- // Get the last decimal on the number.
- temp.last = temp.number.charat(temp.number.length() - 1);
- // Determine whether or not rounding is needed.
- temp.increment = (temp.last >= 5);
- // If it rounds up to another decimal...
- if (temp.tokens[1].length() > 1) {
- temp.last = temp.tokens[1].charat(temp.tokens[1].length() - 2) + temp.increment;
- temp.rounded = temp.tokens[1].substring(0, temp.tokens[1].length() - 2) @ temp.last;
- return temp.tokens[0] @ "." @ temp.rounded;
- } else {
- return int(temp.tokens[0] + temp.increment);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment