モジュール:サンドボックス/D20171232/JaJpNumberFormat
表示
local JaJpNumberFormat = {}
function JaJpNumberFormat.KonnitihaAkatyan(frame)
return "こんにちは、[[赤ちゃん]]。私が{{ママ}}よ。"
end
function JaJpNumberFormat.format (frame)
local args = require('Module:Arguments').getArgs(frame,{})
return string.format (args["1"] or "%s",tonumber(args["2"] or ""))
end
function JaJpNumberFormat.numberFormat (frame)
local args = require('Module:Arguments').getArgs(frame,{})
local value = args["1"] or "0"
value = tonumber(value)
if (value==0) then
return "0"
end
local isNegative = false
if (value < 0) then
isNegative = true
value = value * -1
end
local digits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
local buffer = ""
local decimal = value - math.floor (value)
if (0<decimal) then
value = value - decimal
buffer = "."
local columns = 2
while (0<decimal) do
if (columns==0) then
buffer = buffer .. "|"
end
columns = (columns + 1) % 3
decimal = decimal * 10
local decimal_floor = math.floor(decimal)
buffer = buffer .. digits [decimal_floor]
decimal = decimal - decimal_floor
end
end
local columns = 3
while (0<value) do
if (columns==0) then
buffer = "," .. buffer
end
columns = (columns + 1) % 3
buffer = digits[(value % 10) + 1] .. buffer
value = math.floor(value / 10)
end
if (isNegative) then
buffer = "-" .. buffer
end
return buffer
end
return JaJpNumberFormat