版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/pyf_914406232/article/details/75258591
啥也不说了,直接上代码:
--格式化数字
--超过6位数,截断万位,用万字替代
--超过9位数,截断亿位,用亿字替代
function FormatNumToString(num)
num = num or 0
local s = num;
local len = string.len(tostring(num));
if len >= 6 and len < 9 then
if len <= 8 then
s = string.format("%.1f", num/10000) .. "万"
else
s = string.format("%.0f", num/10000) .. "万"
end
elseif len >= 9 then
if len <= 10 then
s = string.format("%.1f", num/100000000) .. "亿"
else
s = string.format("%.0f", num/100000000) .. "亿"
end
end
return s;
end
function FormatDigitToString(num,limit)
local s = num;
local len = string.len(tostring(num));
if len >= 5 and len < 9 then
s = string.format("%."..limit.."f", num/10000) .. "万"
elseif len >= 9 then
s = string.format("%."..limit.."f", num/100000000) .. "亿"
end
return s;
end
--超过6位数,截断万位,用万字替代
--超过9位数,截断亿位,用亿字替代
function FormatNumToString(num)
num = num or 0
local s = num;
local len = string.len(tostring(num));
if len >= 6 and len < 9 then
if len <= 8 then
s = string.format("%.1f", num/10000) .. "万"
else
s = string.format("%.0f", num/10000) .. "万"
end
elseif len >= 9 then
if len <= 10 then
s = string.format("%.1f", num/100000000) .. "亿"
else
s = string.format("%.0f", num/100000000) .. "亿"
end
end
return s;
end
function FormatDigitToString(num,limit)
local s = num;
local len = string.len(tostring(num));
if len >= 5 and len < 9 then
s = string.format("%."..limit.."f", num/10000) .. "万"
elseif len >= 9 then
s = string.format("%."..limit.."f", num/100000000) .. "亿"
end
return s;
end
看着办吧!!!!