將人民幣的數字表示轉化成大寫表示

2021-08-22 09:11:21 字數 3721 閱讀 8684

'將人民幣的數字表示轉化成大寫表示(vb.net版)

'本**參考chenyu001

'將人民幣的數字表示轉化成大寫表示(c#版)

''改的不多,但願這些改動沒讓原作者發怒

public

class chinesenum

'輸入字串

private _inputstring as

string

'輸出字串,如果無效則輸出錯誤資訊

private _outstring as

string

'判斷輸出字串是否有效

private _valiad as

boolean

public

writeonly

property inputstring() as

string

set(byval value as

string)

_inputstring = value

converttochinesenum()

endsetend

property

public

readonly

property valiad() as

boolean

getreturn _valiad

endgetend

property

public

readonly

property outstring() as

string

getreturn _outstring

endgetend

property

private

sub converttochinesenum()

dim numlist as

string = "零壹貳叄肆伍陸柒捌玖"

dim rmblist as

string = "分角元拾佰仟萬拾佰仟億拾佰仟萬"

dim number as

double = 0

dim tempoutstring as

string

trynumber = double.parse(me._inputstring)

catch ex as systemexception

me._outstring = "傳入引數非數字!"

me._valiad = false

return

endtry

if number > 9999999999999.99 then

me._valiad = false

me._outstring = "超出範圍的人民幣值"

return

endif

dim tempnumberstring as

string = convert.toint64(number * 100).tostring()

dim tempnmberlength as

integer = tempnumberstring.length

dim i as

integer = 0

while i < tempnmberlength

dim onenumber as

integer = int32.parse(tempnumberstring.substring(i, 1))

dim onenumberchar as

string = numlist.substring(onenumber, 1)

dim onenumberunit as

string = rmblist.substring(tempnmberlength - i - 1, 1) if

not (onenumberchar = "零") then

tempoutstring += onenumberchar + onenumberunit

else

if onenumberunit = "億" orelse onenumberunit = "萬" orelse onenumberunit = "元" orelse onenumberunit = "零" then

while tempoutstring.endswith("零")

tempoutstring = tempoutstring.substring(0, tempoutstring.length - 1)

endwhile

endif

if onenumberunit = "億" orelse (onenumberunit = "萬" andalso

not tempoutstring.endswith("億")) orelse onenumberunit = "元" then

tempoutstring += onenumberunit

else

dim tempend as

boolean = tempoutstring.endswith("億")

dim zeroend as

boolean = tempoutstring.endswith("零")

if tempoutstring.length > 1 then

dim zerostart as

boolean = tempoutstring.substring(tempoutstring.length - 2, 2).startswith("零") if

not zeroend andalso (zerostart orelse

not tempend) then

tempoutstring += onenumberchar

endifelse

ifnot zeroend andalso

not tempend then

tempoutstring += onenumberchar

endifend

ifend

ifend

ifi += 1

endwhile

while tempoutstring.endswith("零")

tempoutstring = tempoutstring.substring(0, tempoutstring.length - 1)

endwhile

while tempoutstring.endswith("元")

tempoutstring = tempoutstring + "整"

endwhile

me._outstring = tempoutstring

me._valiad = true

endsub

endclass

'則試方法

dim m as

new chinesenum

private

sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click

m.inputstring = me.textbox1.text

if m.valiad then

me.textbox2.text = m.outstring

me.textbox3.text = string.empty

else

me.textbox2.text = string.empty

me.textbox3.text = m.outstring

endifend

sub

將人民幣的數字轉化成大寫表示 asp

call money 1605893.21 function money thenumber dim money,i,string1,string2,length,checkp 定義變數 dim one onestr 定義陣列 string1 零壹貳叄肆伍陸柒捌玖 string2 萬仟佰拾億仟佰拾萬...

將人民幣轉化為大寫

package org.cric.util public class moneychange 段內位置表示 char vunit 段名表示 char digit 數字表示 long midval long value 100 轉化成整形 string valstr string.valueof mi...

數字人民幣

現階段,m1和m2基於商業銀行賬戶,已實現電子化或數位化,沒有用數字貨幣再次數位化的必要。相比之下,現有紙鈔和硬幣的發行 印製 回籠和貯藏等環節成本較高,流通體系層級多,且攜帶不便 易被偽造 匿名不可控,存在被用於洗錢等違法犯罪活動的風險,實現數位化的必要性與日俱增。央行數字貨幣保持了現鈔的屬性和主...