Coder Social home page Coder Social logo

aiialzy / chinese-number Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 11 KB

chinese-number是一个用于解析和编码中文数字的库.(chinese-number is a package that using to parse chinese number into number and convert number into chinese number. )

License: MIT License

Go 100.00%
chinese chinese-number number number-to-words number-conversion number-converter

chinese-number's Introduction

chinese-number

chinese-number是一个用于解析和编码中文数字的库.

安装

$ go get -u github.com/aiialzy/chinese-number

导入

import cn "github.com/aiialzy/chinese-number"

用法

解析中文数字

han := "一亿一万一千一百一十一"
num, _ := cn.Parse(han)
fmt.Println(num, han)

// 输出
// 100011111 一亿一万一千一百一十一

编码中文数字

num := 1<<63 - 1
han, _ := cn.Convert(num)
fmt.Println(num, han)

// 数字
// 9223372036854775807 九百二十二亿三千三百七十二万零三百六十八亿五千四百七十七万五千八百零七

基准测试

goos: linux
goarch: amd64
pkg: github.com/aiialzy/chinese-number
cpu: AMD Ryzen 5 3600 6-Core Processor

Benchmark name (1) (2) (3) (4)
BenchmarkParse 627830 1882 ns/op 144 B/op 1 allocs/op
BenchmarkConvert 525127 2273 ns/op 1144 B/op 17 allocs/op
  • (1): 一秒之内执行的次数, 数值越大越好
  • (2): 单次执行时间 (ns/op), 数值越小越好
  • (3): 堆内存 (B/op), 数值越小越好
  • (4): 平均每次执行分配次数, 数值越小越好

chinese-number's People

Contributors

aiialzy avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.