MyNixOS website logo
Description

Convert Arabic Numerals to Kansuji.

Simple functions to convert given Arabic numerals to Kansuji numerical figures that represent numbers written in Chinese characters.

arabic2kansuji

{arabic2kansuji} is a package consisting of Simple functions to convert given Arabic numerals to “Kansuji” numerical figures that represent numbers written in Chinese characters.

Installation

You can install the released version of {arabic2kansuji} from CRAN with:

install.packages("arabic2kansuji")

and also, install the development version install from GitHub:

install.packages("remotes")
remotes::install_github("indenkun/arabic2kansuji")

Example

load library.

library(arabic2kansuji)

arabic2kansuji

arabic2kansuji is a function that converts Arabic numerals to Kansuji verbatim.

There is no need to enclose only half-width Arabic numerals with double-quotation marks.

arabic2kansuji(1234567890)
#> [1] "一二三四五六七八九〇"

If you give a string containing Arabic numerals, everything else is retained except the Arabic numerals to be converted. Strings containing Arabic numerals can be converted, but please enclose them in double-quotations

arabic2kansuji("昭和64年は1989年1月7日までです。")
#> [1] "昭和六四年は一九八九年一月七日までです。"

By default, it converts only half-width Arabic numerals, but you can also convert only full-width Arabic numerals or convert both full-width and half-width Arabic numerals to Kansuji by specifying arguments.

# By default, full-width Arabic numerals will not be converted.
arabic2kansuji("東京都新宿区西新宿2丁目8−1")
#> [1] "東京都新宿区西新宿2丁目8−1"
# It can convert full-width Arabic numerals by providing an argument.
arabic2kansuji("東京都新宿区西新宿2丁目8−1", width = "full")
#> [1] "東京都新宿区西新宿二丁目八−一"
arabic2kansuji("全角アラビア数字123と半角アラビア数字123の混在も引数を指定すると変換できます。", width = "all")
#> [1] "全角アラビア数字一二三と半角アラビア数字一二三の混在も引数を指定すると変換できます。"

By default, 0 is converted to rei (〇), but it can be converted to zero (零) by specifying an argument.

arabic2kansuji("令和2年は2020年")
#> [1] "令和2年は二〇二〇年"
arabic2kansuji("令和2年は2020年", zero = "zero")
#> [1] "令和二年は二零二零年"

Since this function only replaces Arabic numerals with Kansuji verbatim, it cannot be converted by calculating 1234 as 千二百三十四. This feature is provided by the arabic2kansuji_num functions.

arabic2kansuji_num

This arabic2kansuji_num calculates and converts a given number to a kanji value. For example, 1234 can be converted to 千二百三十四.

arabic2kansuji_num(124271318)
#> [1] "一億二千四百二十七万千三百十八"

However, currently only accept one half-width Arabic numerals.

Use arabic2kansuji_num if you want to convert two or more half-width Arabic numerals by calculating the number of Chinese characters. You can also use arabic2kansuji_all to convert full-width Arabic numerals (as a string) to Kansuji.

arabic2kansuji_num("124271318人")
#> Warning in .f(.x[[i]], ...): only number can convert to kansuji.
#> [1] NA

Use arabic2kansuji_all to calculate and convert Arabic numerals to Kansuji while keeping the string in Arabic numerals containing the string.

For more than 17 digits, a warning is given because calculation processing may not be performed correctly due to problems on the R.

arabic2kansuji_num(1234567890123456789)
#> Warning in .f(.x[[i]], ...): too long number to convert exactly.
#> [1] "百二十三京四千五百六十七兆八千九百一億二千三百四十五万六千七百六十八"

Negative values are also supported. The notation will be 負Kansuji.

arabic2kansuji_num(-123456789)
#> [1] "負一億二千三百四十五万六千七百八十九"

Too large values (more than 10 to the power of 20) cannot be calculated.

arabic2kansuji_num(100000000000000000000)
#> Warning in .f(.x[[i]], ...): too large number to convert.
#> [1] NA

arabic2kansuji_num accepts two or more Arabic numerals, calculates and converts them to Kansuji.

x <- c(123, 456, 789)
arabic2kansuji_num(x)
#> [1] "百二十三"   "四百五十六" "七百八十九"

arabic2kansuji_all

arabic2kansuji_num only accepts half-width Arabic numbers, but arabic2kansuji_all can convert a string containing a half-width Arabic number to Kansuji and keep the string. arabic2kansuji_all can convert not only half-width Arabic numerals but also full-width Arabic numerals can be converted by specifying an argument. However, it is not possible to convert only the full-size Arabic numerals in the string and keep the half-size Arabic numerals.

arabic2kansuji_all("昭和64年は1989年1月7日までです。")
#> [1] "昭和六十四年は千九百八十九年一月七日までです。"
arabic2kansuji_all("平成31年は2019年4月30日までです。")
#> [1] "平成31年は二千十九年四月三十日までです。"
arabic2kansuji_all("平成31年は2019年4月30日までです。", widths = "all")
#> [1] "平成三十一年は二千十九年四月三十日までです。"

arabic2kansuji_all can receive more than one string.

x <- c("昭和64年は1989年1月7日までです。", "平成31年は2019年4月30日までです。")
arabic2kansuji_all(x)
#> [1] "昭和六十四年は千九百八十九年一月七日までです。"
#> [2] "平成三十一年は二千十九年四月三十日までです。"

arabic2kansuji_all can also convert Arabic numerals and Kansuji intended for digits to represent a single number, such as 1億2345万 intended for 一億二千三百四十五万. This is a kind of side effect that happens when Arabic numbers are converted to Kansuji because the readings are just the same.

arabic2kansuji_all("1億2345万")
#> [1] "一億二千三百四十五万"

Imports packages

  • {purrr}
  • {stringr}
  • {stats}

Known Issue

  • arabic2kansuji_all a combination of Arabic and Kansuji representing a single number of digits, such as tens or billions, but not including the next upper tens or billions of digits, such as 12345万, which is intended to be 一億二千三百四十五万, would be valued at 一万二千三百四十五 in the Arabic numeral place and would not appear in the intended form. There is currently no error on this issue.
arabic2kansuji_all("12345万")
#> [1] "一万二千三百四十五万"
  • arabic2kansuji_* does not support conversion of values greater than one hundred quintillion. Entering a value greater than one hundred quintillion will return a warning message and NA.
arabic2kansuji_num(1e+20)
#> Warning in .f(.x[[i]], ...): too large number to convert.
#> [1] NA
arabic2kansuji_all("100000000000000000000個")
#> Warning in .f(.x[[i]], ...): too large number to convert.
#> [1] NA

License

MIT.

Metadata

Version

0.1.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows