我写的一个,判断一个整数是否能被1除尽的算法,看是否能完善下
--ADD BY FWANG 2011.1.6 判断总箱件数是否能平分 ,能返回1,不能则返回-1
FUNCTION IS_ROUND_ASN_LINE_SETS(P_QUANTITY_SHIPPED IN NUMBER,NUM_OF_CONTAINERS IN NUMBER)
RETURN NUMBER IS
V_RESULT NUMBER;
V_RESULT_TEM NUMBER;
BEGIN
IF P_QUANTITY_SHIPPED > 0 AND NUM_OF_CONTAINERS > 0 THEN
V_RESULT := ROUND(1/(NUM_OF_CONTAINERS/P_QUANTITY_SHIPPED),8); --四舍五入8位小数
V_RESULT_TEM := ROUND(1/(NUM_OF_CONTAINERS/P_QUANTITY_SHIPPED),4); --四舍五入4位小数
IF V_RESULT = V_RESULT_TEM THEN --比较两位小数是否相等,从而得出每套箱数是否能平分
V_RESULT := 1;
ELSE
V_RESULT := -1;
END IF;
END IF;
RETURN V_RESULT;
END;
FUNCTION IS_ROUND_ASN_LINE_SETS(P_QUANTITY_SHIPPED IN NUMBER,NUM_OF_CONTAINERS IN NUMBER)
RETURN NUMBER IS
V_RESULT NUMBER;
V_RESULT_TEM NUMBER;
BEGIN
IF P_QUANTITY_SHIPPED > 0 AND NUM_OF_CONTAINERS > 0 THEN
V_RESULT := ROUND(1/(NUM_OF_CONTAINERS/P_QUANTITY_SHIPPED),8); --四舍五入8位小数
V_RESULT_TEM := ROUND(1/(NUM_OF_CONTAINERS/P_QUANTITY_SHIPPED),4); --四舍五入4位小数
IF V_RESULT = V_RESULT_TEM THEN --比较两位小数是否相等,从而得出每套箱数是否能平分
V_RESULT := 1;
ELSE
V_RESULT := -1;
END IF;
END IF;
RETURN V_RESULT;
END;
问下,红色字体部分是否可以再优化下.
注意:
整数值 = NUM_OF_CONTAINERS/P_QUANTITY_SHIPPED