i working calculations - time use bigdecimal. have created special util make easier make comparisons:
public class bigdecimalutil { public static boolean iszero(bigdecimal value) { return value == null?false:value.compareto(bigdecimal.zero) == 0; } public static boolean ispositive(bigdecimal value) { return value == null?false:value.compareto(bigdecimal.zero) > 0; } public static boolean isnegative(bigdecimal value) { return value == null?false:value.compareto(bigdecimal.zero) < 0; } public static boolean isequal(bigdecimal value1, bigdecimal value2) { return value1.compareto(value2) == 0; } public static boolean islessthan(bigdecimal value1, bigdecimal value2) { return value1.compareto(value2) < 0; } public static boolean ismorethan(bigdecimal value1, bigdecimal value2) { return value1.compareto(value2) > 0; } }
but not comfortable use times. there way add functionality directly bigdecimal class?
lets this:
bigdecimal number = new bigdecimal("0"); if(number.ispositive){ //do }
in case ispositive function util.
it's not possible unless you're willing extend bigdecimal
class, in case can try this:
public class bigdecimal2 extends bigdecimal { public boolean ispositive() { return compareto(bigdecimal.zero) > 0; } //... }
Comments
Post a Comment