Module:Decimal-align

--Align numbers in table cells on the decimal point	
local p = {}

function p.main(frame)
	local input_string_raw = frame.args[1]
	string = frame:preprocess( input_string_raw )

	local left_percent_default = tonumber(frame.args['left'])
	local left_percents = {}
	left_percents[1] = tonumber(frame.args['left1'])
	left_percents[2] = tonumber(frame.args['left2'])
	left_percents[3] = tonumber(frame.args['left3'])
	left_percents[4] = tonumber(frame.args['left4'])
	left_percents[5] = tonumber(frame.args['left5'])
	left_percents[6] = tonumber(frame.args['left6'])
	left_percents[7] = tonumber(frame.args['left7'])
	left_percents[8] = tonumber(frame.args['left8'])
	left_percents[9] = tonumber(frame.args['left9'])
	left_percents[10] = tonumber(frame.args['left10'])

	local column = 1
	for number in mw.ustring.gmatch( string, '%|[%d%.,]+' ) do
		local left_percent = left_percents[column] or left_percent_default or 50
		local right_percent = 100 - left_percent
		column = column + 1
		
		left_string = mw.ustring.sub(mw.ustring.match(number, '^%|[%d, ]*'),2)
		right_string = mw.ustring.match(number, '%.[%d ]*$')
		if left_string == '' then left_string = '0' end
		formatted_number = '%|<span style=\"float: left; text-align: right; width: ' .. tostring(left_percent) .. '%;\">' .. left_string .. '</span>'
		if right_string then
			formatted_number = formatted_number .. '<span style=\"float: right; text-align: left; width: ' .. tostring(right_percent) .. '%;\">' .. right_string .. '</span>'
		end
		string = mw.ustring.gsub( string, number, formatted_number )
	end

	return string
	end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.