- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我必须在 52/200005/0001 之类的数字上添加一个 2 位数的支票(除以 97 的余数)(必须忽略斜线)。
我的代码如下,但由于数字太大而失败:
AppendCheckDigits <- function (x) {
stopifnot(is.character(x) & length(x) == 1 & nchar(x) == 14)
cd <- as.integer(paste(substring(x, 1, 2),
substring(x, 4, 9),
substring(x, 11, 14), sep="")) %% 97
paste(x, "/", cd, sep="")
}
测试它:
AppendCheckDigits("52/200005/0001")
我该如何解决?
最佳答案
integer
类的对象被限制为大约 2*10^9。您应该在函数中使用 as.numeric
而不是 as.integer
:
AppendCheckDigits <- function (x) {
stopifnot(is.character(x) & length(x) == 1 & nchar(x) == 14)
cd <- as.numeric(paste(substring(x, 1, 2),
substring(x, 4, 9),
substring(x, 11, 14), sep="")) %% 97
paste(x, "/", cd, sep="")
}
然后:
> AppendCheckDigits("52/200005/0001")
[1] "52/200005/0001/43"
请注意,您可以通过这种方式矢量化和简化您的函数,例如:
AppendCheckDigits <- function (x) {
stopifnot(is.character(x) & nchar(x) == rep(14,length(x)))
num <- as.numeric(gsub("/","", x)) %% 97
return(paste0(x, "/", num))
}
然后:
> AppendCheckDigits(c("52/200005/0001", "52/200005/0021"))
[1] "52/200005/0001/43" "52/200005/0021/63"
关于r - 如何计算 R 中大数的校验位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26181437/
我们在 RedHat 中使用 Postgres 9.2。我们有一个类似于以下的表: CREATE TABLE BULK_WI ( BULK_ID INTEGER NOT NULL, U
根据我的计算,将浮点值转换为计算机存储的二进制值(符号、指数、尾数格式),在 32 位中,1 位用于符号,8 位用于指数。 所以只剩下 23 位来表示数字。 所以我认为具有正确行为的浮点值范围仅为 0
我有一个像这样的临时表: CREATE TABLE `staging` ( `created_here_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTA
下面是我的 HTML: Fact Sheet Facilities and Administrative (F&A) Cost Agreem
我想知道为什么 .add(i, E) 是 O(n) 而 .get(i) 是 O(1)?是不是因为 n 元素在插入后必须向右移动? 最佳答案 记住大 O 表示法显示问题的数量级而不是最佳情况解决方案..
我在装有 GCC 4.8.2 的 Windows 8.1、Intel i7-3517U 64 位笔记本电脑上测试这个简单的 C++ 代码。 #include using namespace std;
我是一名优秀的程序员,十分优秀!