使用命令行选项时如何在 CasperJS 中保留长数字?

How to preserve long numbers in CasperJS when using command line options?

执行此操作时:

casperjs somescript.js --number=736280854938322517687376855643288785

在代码中:

var casper = require('casper').create();
var value = casper.cli.get("number");

console.log(value); // yields: 7.3628085493832246e+35
                    // want: 736280854938322517687376855643288785

我看了又看,思考和破解,但运气不佳。简单的解决方案似乎只是将数字转换为字符串。或者将数字作为字符串传递。但是我不明白这个语法。

参见Raw parameter values

By default, the cli object will process every passed argument & cast them to the appropriate detected type[...]

您需要使用 casper.cli.raw.get("number") 来获取未解析的值。因为大于 253 的整数值不能表示为整数 without losing precision, you would need to work with them as a string or use some big integer library (such as JSBN).