-- 数字字符串转换成中文大写
function ToolKit.transformNumberString(numberStr)
if numberStr ~= nil then
local tmpNum = tonumber(numberStr)
if tmpNum > 0 then
local name = { "", "拾", "佰", "仟", "万", "拾万", "佰万", "仟万", "亿", "拾亿", "佰亿", "仟亿", "万亿" }
local baseValue = 10 ^ 0
local index = 0
local tmpString = ""
local isZero = true
while (baseValue <= tmpNum) do
local newValue = math.floor(tmpNum / baseValue) % 10
if newValue == 0 then
if isZero == false then
tmpString = '零' .. tmpString
isZero = true
end
else
isZero = false
local dw = name[index + 1]
if string.len(dw) > 3 then
local lastStr = string.sub(dw, 4)
if string.find(tmpString, lastStr) ~= nil then
dw = string.sub(dw, 0, 3)
end
end
tmpString = ToolKit.commonNumberTrasform(newValue) .. dw .. tmpString
end
index = index + 1
baseValue = 10 ^ index
end
return tmpString
end
end
return nil
end
数字转中文
最新推荐文章于 2022-06-15 14:50:40 发布