將貨幣轉換為大寫VB

2021-05-25 10:06:58 字數 3009 閱讀 1160

public class convertmoney

'輸入字串

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()

end set

end property

public readonly property valiad() as boolean

getreturn _valiad

end get

end property

public readonly property outstring() as string

getreturn _outstring

end get

end 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

end try

if number > 9999999999999.99 then

me._valiad = false

me._outstring = "傳入的值超出了範圍!"

return

end if

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)

end while

end if

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

end if

else

if not zeroend andalso not tempend then

tempoutstring += onenumberchar

end if

end if

end if

end if

i += 1

end while

while tempoutstring.endswith("零")

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

end while

while tempoutstring.endswith("元")

tempoutstring = tempoutstring + "整"

end while

me._outstring = tempoutstring

me._valiad = true

end sub

end class

將數字轉換為大寫金額

export const changetochinese num num num.replace g,替換tomoney 中的 num num.replace g,替換tomoney 中的空格 num num.replace g,替換掉可能出現的 字元 if isnan num 字元處理完畢後開始轉...

浮點數轉換為大寫貨幣金額

浮點數轉換為大寫貨幣金額 author bobby public class convertfloatnumtormbformat private static string moneyunitarray private static string decimalarray 把數字分成整數部分和小數...

AnglurJS將金額轉換為大寫金額

class font small style div 後台 scope.milestone.winbiddate new date 前台就會顯示出這種效果來 根據相同的原理我做了乙個阿拉伯數字轉換大寫數字的過濾convertcurrencyfilter 過濾的 如下 validate input s...