在莲花脚本中执行22位数字的划分 [英] Perform division of a 22 digit number in lotus script

查看:109
本文介绍了在莲花脚本中执行22位数字的划分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想进行22位数的分割。在莲花剧本。

I want to perform division of a 22 digit no. in lotus script.

任何人都可以告诉我该怎么做?我没有得到正确的结果。

Can anyone please tell me how to do it? I am not getting the correct result.

例如;

dim num为Double;

dim num as Double;

dim num1为Double;

dim num1 as Double;

num = 123456789989898976765;

num=123456789989898976765;

num1 = num / 97;

num1 = num / 97;

但是我没有在num1中得到正确的结果。

but i am not getting the correct result in num1.

推荐答案

为了满足我的数学家,我必须告诉你,你永远不会得到正确的答案,分裂产生一个有无限小数的数字,但我得到了你的'我想,重新开始。您想要的号码是:

To satisfy the mathematician in me, I have to tell you that you're never going to get the "correct" answer, the division produces a number that has an infinite decimal, but I get what you're after, I think. The number you want is:

1 272 750 412 266 999 760.463 917 525 ...

但你获得的数字是:

1 272 750 412 266 999 800

这是由于语言使用的数字格式缺乏精确性。当您进行除法时,不会发生精度损失,只要将常量分配给变量,它就会发生得更快。您想要存储的数字是:

This is due to the lack of precision in the number format used by the language. The loss of precision doesn't occur when you do the division, it happens much sooner than that, as soon as you assign the constant to the variable. The number you want to store is:

123 456 789 989 898 976 765

实际存储的数字是:

123 456 789 989 898 980 000



<这就是导致错误答案的原因。

This is what results in the wrong answer.

由于我不知道Lotus Script环境,我会做两件事;首先,给你一些代码来解决这个特殊的问题,如下所示:

Since I don't know the Lotus Script environment, I will do two things; first, give you some code that will fix this particular problem, like so:

var num = [12345678998, 9898976765];
var num1 = num[0] / 97;
var num2 = Math.floor(num1);
num2 = num1 - num2;
num2 *= 97;
num2 = Math.round(num2)
num2 *= Math.pow(10, num[1].toString().length);
num2 = (num2 + num[1]) / 97;
alert(Math.floor(num1).toString() + num2.toString());

您可以根据自己的需要进行概括。此代码将分区拆分为两个较小的分区,数字存储格式CAN处理并将第一个分区的剩余部分添加到第二个分区,产生以下结果:

that you can then generalize to fit your needs. This code splits the division into two smaller divisions that the number storage format CAN handle and adds the remainder of the first division to the second, producing this result:

1 272 750 412 266 999 760.463 917 7

这不完全正确,但可能足够接近吧?如何将较大的数字拆分成碎片而不会失去精确度,这就是你的两个问题。 (提示:使用字符串)

which isn't exact, but probably close enough, right? How you split the bigger number into fragments without loosing precision is left up two you. (Hint: use strings)

其次,我将指向 BigInt.js ,一个用于在JavaScript中使用任意大整数进行数学运算的库。如果你可以将这个库包含在你的代码中,那肯定是更经济的方式。

Second, I will point you to BigInt.js, a library for doing math with arbitrarily large integers in JavaScript. If you can include this library into your code, it is definitely the more economical way to go.

我希望其中一个有帮助。

I hope one of these helps.

这篇关于在莲花脚本中执行22位数字的划分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆