PitBull4 數值單位換算再修正

好像有點玩上癮了,
用了一天發現數值判斷還要再調整一下,
畢竟用的單位變小(百萬→萬),
數字也就變大了,
為了配合PitBull短格式的設計我多寫了一條判斷,
當數值達一百萬以上不顯示小數點以下的數字,
看起來比較不會一長串佔空間的感覺。

以 PitBull4_DogTagTexts\libs\LibDogTag-3.0\Categories\TextManip.lua 這檔案為例,
在函式 DogTag:AddTag(“Base”, “Short”) 中的 if type(value) == “number” 下的起頭多加一項判斷:

if type(value) == "number" then
  if value >= 100000 or value <= -100000 then
    return ("%.1f萬"):format(value / 10000)
  elseif value >= 10000 or value <= -100000 then
    return ("%.2f萬"):format(value / 10000)
  --elseif value >= 100000 or value <= -100000 then
  --	return ("%.0fk"):format(value / 1000)
  --elseif value >= 10000 or value <= -10000 then
  --	return ("%.1fk"):format(value / 1000)
  else
    return math.floor(value+0.5)..''
  end
else

所以又做了一些修正:

if type(value) == "number" then
  if value >= 1000000 or value <= -1000000 then
    return ("%.0f萬"):format(value / 10000)
  elseif value >= 100000 or value <= -100000 then
    return ("%.1f萬"):format(value / 10000)
  elseif value >= 10000 or value <= -100000 then
    return ("%.2f萬"):format(value / 10000)
  --elseif value >= 100000 or value <= -100000 then
  --	return ("%.0fk"):format(value / 1000)
  --elseif value >= 10000 or value <= -10000 then
  --	return ("%.1fk"):format(value / 1000)
  else
    return math.floor(value+0.5)..''
  end
else

其他幾個地方也要加入同等的判斷。

成果:
pitbull4_textfix

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料