Use VB to transfer numbers to Chinese strings

zhaozj2021-02-16  44

Depending on the number of reading, a program parameter that converts a digital to a Chinese string is a digital parameter is whether it is inverse to renovicate uppercase parameter three is whether it is directly read the number, otherwise it has a hundred and other units. The parameter 4 is the number of bits behind the decimal point, and the default is that the use method is t = getChinanum (20005.000436,,, 7) 'Return "Two thousand and 5:23" T = getChinanum (2005.436, true, 7) 'Return "仟 伍 元 肆 角" T = getChinanum (2005.436, True, 7)' Return "2005 Four Third 6"

Below is the program code

FUNCTION

GetChinanum (OtherNum

AS

Double

, Optional ISRMB

AS

Boolean

OPTIONAL NumOption

AS

Boolean

OPTIONAL DOTNUM

AS

Integer

)

AS

String

On

Error

Resume

NEXT

Num

=

TRIM

(Str

Int

(Othernum))))))))

IF

ISRMB

THEN

Numwei

=

"

Pick up 仟 万 拾 仟

"

Numshu

=

"

Zero 壹 贰 伍 柒捌 柒捌 柒捌 柒捌

"

Else

Numwei

=

"

Ten hundreds of tens of hundred billion billion

"

Numshu

=

"

Zero one two three four five six seven eight ninety

"

End

IF

IF

Othernum

<

20

And

Othernum

> =

10

THEN

Num

=

Right

(NUM,

1

GetChinanum

=

Left

(Numwei,

1

)

End

IF

For

i

=

1

TO

Len

(NUM) BSTR

=

MID

(Num, I,

1

)

IF

Numoption

THEN

GetChinanum

=

GetChinanum

MID

(Numshu, Val (BSTR)

1

,

1

)

Else

GetChinanum

=

GetChinanum

MID

(Numshu, Val (BSTR)

1

,

1

)

IF

BSTR

=

"

0

"

THEN

IF

MID

(Numwei,

Len

(NUM)

-

i,

1

)

=

"

Ten thousand

"

Oral

MID

(Numwei,

Len

(NUM)

-

i,

1

)

=

"

Billion

"

THEN

DO

While

Right

(GetChinanum,

1

)

=

"

zero

"

GetChinanum

=

Left

(GetChinanum,

Len

(GetChinanum)

-

1

)

Loop

GetChinanum

=

GetChinanum

MID

(Numwei,

Len

(NUM)

-

i,

1

)

End

IF

Else

GetChinanum

=

GetChinanum

MID

(Numwei,

Len

(NUM)

-

i,

1

)

End

IF

GetChinanum

=

Replace

(GetChinanum,

"

Zero zero

"

,

"

zero

"

)

End

IF

NEXT

i

IF

Numoption =

False

THEN

DO

While

Right

(GetChinanum,

1

)

=

"

zero

"

GetChinanum

=

Left

(GetChinanum,

Len

(GetChinanum)

-

1

)

Loop

End

IF

IF

ISRMB

THEN

Numrmb

=

"

Elementary point

"

GetChinanum

=

GetChinanum

MID

(NumRMB,

1

,

1

)

IF

Val (NUM)

<>

Othernum

THEN

Num

=

TRIM

(Str

Round

(Othernum)

-

Val (NUM),

2

)))))))

For

i

=

2

TO

Len

(NUM) BSTR

=

MID

(Num, I,

1

GetChinanum

=

GetChinanum

MID

(Numshu, Val (BSTR)

1

,

1

)

MID

(NumRMB, I,

1

)

NEXT

i

Else

GetChinanum

=

GetChinanum

"

whole

"

End

IF

Else

IF

Val (NUM)

<>

Othernum

THEN

IF

Dotnum

=

0

THEN

DotNum

=

4

Num

=

TRIM

(

CSTR

(

Round

(Othernum)

-

Val (Num), Dotnum))))

IF

GetChinanum

=

""

THEN

GetChinanum

=

"

zero

"

GetChinanum

=

GetChinanum

"

point

"

For

i

=

2

TO

Len

(NUM) BSTR

=

MID

(Num, I,

1

GetChinanum

=

GetChinanum

MID

(Numshu, Val (BSTR)

1

,

1

)

NEXT

i

End

IF

End

IF

END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-27335.html

New Post(0)