Aug
13
2011

Function: Integer to Roman numerals

Small function for converting integer into roman numbers. ie 2012 = MMXII

// Integer to Roman numerals - mgear - http://unitycoder.com/blog/
// Unity3D version converted from this: http://rosettacode.org/wiki/Roman_numerals/Encode

function int2roman(value:int)
{
var arabic=new Array(1000, 900, 500, 400, 100, 90, 50,  40,  10,  9,  5,   4,  1);
var roman=new Array("M", "CM", "D","CD", "C","XC","L","XL","X","IX","V","IV","I");
var i:int;
var result="";
for (i = 0; i < 13; i++)
{
while (value >= arabic[i])
{
result = result + roman[i].ToString();
value  = value - arabic[i];
}
}
return result;
}

function Start()
{
print("2012:"+int2roman(2012));
}

2 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.