我想计算太阳围绕银河系的情况;the Math Formula is ((241828072282107.5071453596951 * 666) * 2) * 3.14159265359, using QML JavaScript I get the answer 1011954093357316100, when the correct answer is 1011954093357316200, a 100 miles off.
galaxyRadius="241828072282107.5071453596951";
currentTrackNumber=666; // Track Number like on a Record
pIe="3.14159265359"; // not the same as Math.PI
Run Code Online (Sandbox Code Playgroud)
我必须使用字符串,因为将这些大小的数字转换为浮点数会截断精度,我正在转换旧的 bash 脚本,并且它与 bc 一起工作得很好,而不是数学。
我已经尝试过这个:
orbitDist = ((( Number.parseFloat(galaxyRadius).toPrecision(20) * currentTrackNumber) * 2) * Number.parseFloat(pIe).toPrecision(12) );
Run Code Online (Sandbox Code Playgroud)
我得到的结果与以下相同:
orbitDist = ((( galaxyRadius * currentTrackNumber) * 2) * pIe );
Run Code Online (Sandbox Code Playgroud)
来自bash:
echo "$(bc <<< "scale=13;((241828072282107.5071453596951 * …Run Code Online (Sandbox Code Playgroud)