numcn

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2019 License: MIT Imports: 2 Imported by: 8

README

MIT GoDoc Go Report Card

numcn

Interconversion between Chinese numbers & Numbers. 中文数字与数字的相互转换。

Example

func main() {
	chNum := "负十七亿零五十三万七千零一十六"
	num, _ := numcn.DecodeToInt64(chNum)
	fmt.Println(num) // -1700537016
	chNumAgain := numcn.EncodeFromInt64(num)
	fmt.Println(chNumAgain) // 负十七亿零五十三万七千零一十六

	chFloatNum := "负零点零七三零六"
	fNum, _ := numcn.DecodeToFloat64(chFloatNum)
	fmt.Printf("%f\n", fNum) // -0.073060
	chFloatNumAgain := numcn.EncodeFromFloat64(fNum)
	fmt.Println(chFloatNumAgain) // 负零点零七三零六
}

Documentation

Overview

Package numcn provides primitives for Interconversion between Chinese numbers & Numbers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeToFloat64

func DecodeToFloat64(cn string) (float64, error)

DecodeToFloat64 : decode a chinese number string into Float64

func DecodeToInt64

func DecodeToInt64(cn string) (int64, error)

DecodeToInt64 : decode a chinese number string into Int64

func EncodeFromFloat64

func EncodeFromFloat64(num float64) string

EncodeFromFloat64 : convert float64 into Chinese number 由于float64固然存在的精度问题,本函数可能不会特别精准。所以小数部分最多精确到6位。

func EncodeFromInt64

func EncodeFromInt64(num int64) string

EncodeFromInt64 : convert int64 into Chinese number

func MustDecodeToFloat64

func MustDecodeToFloat64(cn string) float64

MustDecodeToFloat64 : decode a chinese number string into Float64 without error

func MustDecodeToInt64

func MustDecodeToInt64(cn string) int64

MustDecodeToInt64 : decode a chinese number string into Int64 without error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL