ColdFusion 太大而不能成为整数 [英] ColdFusion too big to be an integer
本文介绍了ColdFusion 太大而不能成为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将大量数据转换为兆字节.我不要小数
I am trying to convert a large number going in to Megabytes. I don't want decimals
numeric function formatMB(required numeric num) output="false" {
return arguments.num 1024 1024;
}
然后它会抛出一个错误
我该如何解决这个问题?
How do I get around this?
推荐答案
你不能改变 Long 的大小,这是 CF 用于整数的.所以你需要 BigInteger 代替:
You can't change the size of a Long, which is what CF uses for integers. So you'll need to BigInteger instead:
numeric function formatMB(required numeric num) {
var numberAsBigInteger = createObject("java", "java.math.BigInteger").init(javacast("string", num));
var mbAsBytes = 1024 ^ 2;
var mbAsBytesAsBigInteger = createObject("java", "java.math.BigInteger").init(javacast("string", mbAsBytes));
var numberInMb = numberAsBigInteger.divide(mbAsBytesAsBigInteger);
return numberInMb.longValue();
}
CLI.writeLn(formatMB(2147483648));
但正如 Leigh 指出的那样……对于您正在做的事情,您最好还是这样做:
But as Leigh points out... for what you're doing, you're probably better off just doing this:
return floor(arguments.num / (1024 * 1024));
这篇关于ColdFusion 太大而不能成为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文