如果我们有数字,那么我们可能希望将这些数字转换为单词。例如,将1转换为1。如果我们有文本数据并且数字是文本的一部分,则可能需要这样做。因此,最好以文本形式表示数字,以使文本保持一致。这可以通过使用replace_number函数qdap软件包来完成。
安装和加载qdap软件包-
install.packages("qdap") library("qdap")
replace_number("1") [1] "one" replace_number("10") [1] "ten" replace_number("100") [1] "one hundred" replace_number("1000") [1] "one thousand" replace_number("1001") [1] "one thousand one" replace_number("12000") [1] "twelve thousand" replace_number("12214") [1] "twelve thousand two hundred fourteen" replace_number("15748") [1] "fifteen thousand seven hundred forty eight" replace_number("2361414") [1] "two million three hundred sixty one thousand four hundred fourteen" replace_number("321457") [1] "three hundred twenty one thousand four hundred fifty seven" replace_number(c("1","2","3","4","5","6","7","8","9","10")) [1] "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" [10] "ten" replace_number(c("321457","214521","365841")) [1] "three hundred twenty one thousand four hundred fifty seven" [2] "two hundred fourteen thousand five hundred twenty one" [3] "three hundred sixty five thousand eight hundred forty one" replace_number(c("264155","154512","344512","2144","221","14542","35915112","1454221","147232321","14789523")) [1] "two hundred sixty four thousand one hundred fifty five" [2] "one hundred fifty four thousand five hundred twelve" [3] "three hundred forty four thousand five hundred twelve" [4] "two thousand one hundred forty four" [5] "two hundred twenty one" [6] "fourteen thousand five hundred forty two" [7] "thirty five million nine hundred fifteen thousand one hundred twelve" [8] "one million four hundred fifty four thousand two hundred twenty one" [9] "one hundred forty seven million two hundred thirty two thousand three hundred twenty one" [10] "fourteen million seven hundred eighty nine thousand five hundred twenty three"
x <-c(“印度有29个州”)replace_number(x)
[1] "There are twenty nine states in india"
y <-c(“ 1025454人患了covid-19”)replace_number(y)
[1] "one million twenty five thousand four hundred fifty four people suffered from covid-nineteen"
z <-c(“世界上有22个阿拉伯国家”)replace_number(z)
[1] "We have twenty two Arab countries in the world"
v1 <-sample(0:5000,20)v1
[1] 1845 4438 4664 1803 1131 4254 4880 4267 4764 4168 222 3880 534 1319 4998 [16] 370 2657 78 1056 620 replace_number(v1) [1] "one thousand eight hundred forty five" [2] "four thousand four hundred thirty eight" [3] "four thousand six hundred sixty four" [4] "one thousand eight hundred three" [5] "one thousand one hundred thirty one" [6] "four thousand two hundred fifty four" [7] "four thousand eight hundred eighty" [8] "four thousand two hundred sixty seven" [9] "four thousand seven hundred sixty four" [10] "four thousand one hundred sixty eight" [11] "two hundred twenty two" [12] "three thousand eight hundred eighty" [13] "five hundred thirty four" [14] "one thousand three hundred nineteen" [15] "four thousand nine hundred ninety eight" [16] "three hundred seventy" [17] "two thousand six hundred fifty seven" [18] "seventy eight" [19] "one thousand fifty six" [20] "six hundred twenty"
v2 <-sample(100001:999999,20)
v2
[1] 359487 994098 458703 474531 106581 905167 373805 288612 614544 591035 [11] 632526 649772 711979 785355 720779 678609 843081 679009 593148 801554
replace_number(v2)
[1] "three hundred fifty nine thousand four hundred eighty seven" [2] "nine hundred ninety four thousand ninety eight" [3] "four hundred fifty eight thousand seven hundred three" [4] "four hundred seventy four thousand five hundred thirty one" [5] "one hundred six thousand five hundred eighty one" [6] "nine hundred five thousand one hundred sixty seven" [7] "three hundred seventy three thousand eight hundred five" [8] "two hundred eighty eight thousand six hundred twelve" [9] "six hundred fourteen thousand five hundred forty four" [10] "five hundred ninety one thousand thirty five" [11] "six hundred thirty two thousand five hundred twenty six" [12] "six hundred forty nine thousand seven hundred seventy two" [13] "seven hundred eleven thousand nine hundred seventy nine" [14] "seven hundred eighty five thousand three hundred fifty five" [15] "seven hundred twenty thousand seven hundred seventy nine" [16] "six hundred seventy eight thousand six hundred nine" [17] "eight hundred forty three thousand eighty one" [18] "six hundred seventy nine thousand nine" [19] "five hundred ninety three thousand one hundred forty eight" [20] "eight hundred one thousand five hundred fifty four"
我有一个表,它有一个主键列“gid”,它的类型是“Integer NOT NULL”。我想把它转换成“Serial NOT NULL”,这样我就可以在这个表中插入一些值。我使用以下命令将其转换为串行: 此命令将整数转换为串行。但是,当我在表中输入一些数据时,出现了以下错误: 错误:重复的键值违反唯一约束“pk_测试”。 请帮我解决这个问题。是否有其他方法将整数转换为串行?
问题内容: 我需要使用反射获取字段的值。碰巧我并不总是确定该字段的数据类型是什么。为此,为了避免某些代码重复,我创建了以下方法: 并使用如下方法: 要么 问题是我似乎无法转换为: 有没有更好的方法来实现这一目标? 我正在使用Java 1.6。 问题答案: 不,即使可以从转换为,也无法转换为。对于已知为数字的 单个 值,并且想要获得长整型值,可以使用: 对于数组,这将比较棘手…
问题内容: 我有Hibernate方法,它返回给我一个BigDecimal。我有另一个API方法,我需要将该数字传递给它,但是它接受Integer作为参数。我不能更改两种方法的返回类型或变量类型。 现在如何将BigDecimal转换为Integer并将其传递给第二种方法? 有没有解决的办法? 问题答案: 您将致电(或仅致电),如果您丢失了信息,它甚至会引发异常。返回一个int,但是自动装箱可以解决
问题内容: 例如输入:(类型:) 转换示例:(类型:的切片) 问题答案: 除了mhutter的答案外,还请注意您的输入看起来像一个JSON数组(也许是来自JSON文本?)。 如果您这样处理,则可以将其内容编组为一个切片。直接解析其中的数字并不会更快(因为该包使用了反射),但是它肯定更简单: 输出(在Go Playground上尝试):
我想将时间间隔配置存储到数据库中,如下所示: 但是我不知道如何将例如值转换为LocalDateTime,因为我想使用此值来计算SQL查询的时间间隔。 将此值转换为LocaLDateTime的正确方法是什么?
我创建了一个程序,它使用Scanner向用户询问int值,直到他们插入-1,这使得程序停止接收数字。这样做后,它将添加用户输入的所有值。这是我到目前为止的代码: 我希望输出如下所示: 我想用一个字符串来给我输入的数字集,但它只给我最后输入的值。这是-1,因为这是停止程序必须输入的数字。 我怎样才能解决这个问题?