Jump to content

Module:Strip to numbers: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
extract text from nowiki tags
actually, mw.text.unstrip is better as it doesn't leave non-nowiki strip markers hanging around
Line 1: Line 1:
local p = {}
local p = {}
function p.main(frame)
function p.main(frame)
local theString = mw.text.unstripNoWiki(frame.args[1])
local theString = mw.text.unstrip(frame.args[1])
local onlyNumber
local onlyNumber
onlyNumber = (string.match(theString, "%-?[%d%.]+"))
onlyNumber = (string.match(theString, "%-?[%d%.]+"))

Revision as of 03:54, 19 July 2015

local p = {}
function p.main(frame)
	local theString = mw.text.unstrip(frame.args[1])
	local onlyNumber
	onlyNumber = (string.match(theString, "%-?[%d%.]+"))
	checkedNumber = tonumber(onlyNumber)
	if checkedNumber == nil then
		error(" Input did not contain valid numeric data")
	else
		return checkedNumber
	end
end

function p.halve(frame)
	local checkedNumber = (p.main(frame))
	local halvedNumber
	halvedNumber = (checkedNumber / 2)
	return halvedNumber
end
return p