Skip to content

Instantly share code, notes, and snippets.

@kirillrybin
Created October 17, 2014 14:39
Show Gist options
  • Save kirillrybin/6958f9cfc6cb792060f7 to your computer and use it in GitHub Desktop.
Save kirillrybin/6958f9cfc6cb792060f7 to your computer and use it in GitHub Desktop.
Basic NumberUtil
using UnityEngine;
public class NumberUtil{
public static string ToRoman(int number)
{
if ((number < 0) || (number > 3999)) Debug.LogError("insert value betwheen 1 and 3999");
if (number < 1) return string.Empty;
if (number >= 1000) return "M" + ToRoman(number - 1000);
if (number >= 900) return "CM" + ToRoman(number - 900); //EDIT: i've typed 400 instead 900
if (number >= 500) return "D" + ToRoman(number - 500);
if (number >= 400) return "CD" + ToRoman(number - 400);
if (number >= 100) return "C" + ToRoman(number - 100);
if (number >= 90) return "XC" + ToRoman(number - 90);
if (number >= 50) return "L" + ToRoman(number - 50);
if (number >= 40) return "XL" + ToRoman(number - 40);
if (number >= 10) return "X" + ToRoman(number - 10);
if (number >= 9) return "IX" + ToRoman(number - 9);
if (number >= 5) return "V" + ToRoman(number - 5);
if (number >= 4) return "IV" + ToRoman(number - 4);
if (number >= 1) return "I" + ToRoman(number - 1);
Debug.LogError("something bad happened");
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment