I want to do create a class that rounds off a decimal. I’m running into problems and I assume the solution is pretty simple but I’m not finding an answer in the books I have nor in searches.
Here’s what I have:
package {
public class Round {
private var _num:Number;
private var _int:int;
private var _decimal:Number;
public function Round(num:Number):Number {
_num = num;
_int = int(_num);
_decimal = _num - _int;
if (_decimal >= 0.5) {
return _int + 1;
} else {
return _int;
}
}
}
}
First of all, I know that you can’t have a constructor return a value, but I have tried to simply reassign the code to a non-constructor function and still cannot make this work.
Again, I’m sure it’s simple but I’m just not well-versed enough in AS3. How do I make my class return a simple value, so that I can call, for example, Round(2.355) and get 2?
Thanks!