在我的PL-SQL工作中,我经常使用TRUNC函数来检查数字ID中较高位置的值。例如:相当于Oracle的TRUNC功能的Java?
if trunc(idValue,-3)=254000 then...
在Java中是否有类似的方法可用于int/Integer变量?
在我的PL-SQL工作中,我经常使用TRUNC函数来检查数字ID中较高位置的值。例如:相当于Oracle的TRUNC功能的Java?
if trunc(idValue,-3)=254000 then...
在Java中是否有类似的方法可用于int/Integer变量?
你可以利用整除的位置:
public int trunc(int value, int places) {
// places should be positive, not negative
int divisor = Math.pow(10, places);
int tempVal = value/divisor;
int finalVal = tempVal * divisor;
return finalVal;
}
(代码中的某处)
if (trunc(idValue,3)==254000)
我认为你的意思是使用除数的力量('int divisor = Math.pow(10,places);'),而不是乘法, – Mureinik
谢谢@Mureinik –
'Math.round'或'Math.ceil'和一些计算最有可能 – 2016-08-03 18:14:53