如何避免 mathjs 结果中的指数符号

How can I avoid exponential notation in mathjs results

在使用 mathjs 的函数中,希望将结果显示为 1000000000000000000000000000 而不是 1e+27。

我尝试了 math.format() 函数,但没有用。

> x = 1e+27
< 1e+27
> math.format(x, {notation: 'fixed'})
< "1e+27"
> math.format(x, {notation: 'auto', exponential: {lower: 1e-100, upper: 1e+100}})
< "1e+27"

您做对了,您的格式示例都应该有效。

问题是 math.js 在幕后使用了 JavaScript 的 toPrecision,这允许高达 21 位的精度。因此,当您尝试 x=1e20 时,它将 return 您想要的输出,对于 x=1e21 和更大的输出,您将得到指数计数法。

虽然我会称这是一个错误,如果 math.js 支持这个就很好了,如果不支持,至少在尝试配置太大的 lowerupper 值。我在 github 项目中为此创建了一个问题:https://github.com/josdejong/mathjs/issues/291