lua写一个g转换为kg的方法

来源:互联网 发布:算法工程师职业怎么样 编辑:程序博客网 时间:2024/04/30 08:53
local function g_convert_kg(info)    if info["weight"] and (string.find(info["weight"], "k") or info["weight"] =="0") thenprint(info["weight"])print("不用修改")    elseif info["weight"] then             local weight_num=string.sub(info["weight"],0,string.len(info["weight"])-1)        local weight_kg=string.format("%0.3f", weight_num/1000)        while(string.sub(weight_kg,string.len(weight_kg),string.len(weight_kg))=="0")        do            weight_kg=string.sub(weight_kg,0,string.len(weight_kg)-1)        end        if (string.sub(weight_kg,string.len(weight_kg),string.len(weight_kg))==".")then            weight_kg=string.sub(weight_kg,0,string.len(weight_kg)-1)        end        info["weight"] = weight_kg.."kg" print("修改成功")    end        print(info["weight"])endinfo={}info["weight"]="422001g"g_convert_kg(info)

0 0
原创粉丝点击