# 保留两位小数 def number_to_capital_zh(strno=nil) cCha = [['零元','零拾','零佰','零仟','零万','零亿','亿万','零零零','零零','零万','零亿','亿万','零元'], [ '元','零','零','零','万','亿','亿','零','零','万','亿','亿','元']] strno = strno.to_s.split(".") return "零元" if strno.blank? if strno.size > 1 result = (change_unit(strno.first.split("").reverse,"first").reverse + change_unit(strno.last.to_f.round(2).split(""),"last")).join("") else result = (change_unit(strno.first.split("").reverse,"first").reverse).join("") +"整" end for m in 0..12 result_number = result.gsub!(cCha[0][m], cCha[1][m]) end return result_number end def change_unit(aske_no,unit) unit = %w(角 分) if unit == "last" unit = %w(元 拾 佰 仟 万 拾 佰 仟 亿 拾 佰 仟 万 拾 佰 仟) if unit == "first" number = {"0"=>"零","1"=>"壹","2"=>"贰","3"=>"叁","4"=>"肆","5"=>"伍","6"=>"陆","7"=>"柒","8"=>"捌","9"=>"玖"} result = [] aske_no.each_with_index do |no,index| result << number[no] + unit[index] end result end test: number_to_capital_zh(324324.234343) => "叁拾贰万肆仟叁佰贰拾肆元贰角叁分" number_to_capital_zh(32432443242343) => "叁拾贰万肆仟叁佰贰拾肆亿肆仟叁佰贰拾肆万贰仟叁佰肆拾叁元整" number_to_capital_zh(111000100100) => "壹仟壹佰壹拾亿零壹拾万零壹佰元整" number_to_capital_zh(11100010000) => "壹佰壹拾壹亿零壹万元整" number_to_capital_zh(1110000000) => "壹拾壹亿壹仟万元整" number_to_capital_zh(1010000000) => "壹拾亿壹仟万元整"
付款数字转中文大写
猜你喜欢
转载自schooltop.iteye.com/blog/2317150
今日推荐
周排行