Summary
This formula will convert a number to a roman numeral in Power Apps. The number must be within the range of 1-3999.
Example
Inputs
Number | 13 |
Code
With(
{
varNumber: 13,
varRoman: {
Units: Table(
{
val: "I",
key: "1"
},
{
val: "II",
key: "2"
},
{
val: "III",
key: "3"
},
{
val: "IV",
key: "4"
},
{
val: "V",
key: "5"
},
{
val: "VI",
key: "6"
},
{
val: "VII",
key: "7"
},
{
val: "VIII",
key: "8"
},
{
val: "IX",
key: "9"
}
),
Tens: Table(
{
val: "X",
key: "10"
},
{
val: "XX",
key: "20"
},
{
val: "XXX",
key: "30"
},
{
val: "XL",
key: "40"
},
{
val: "L",
key: "50"
},
{
val: "LX",
key: "60"
},
{
val: "LXX",
key: "70"
},
{
val: "LXXX",
key: "80"
},
{
val: "XC",
key: "90"
}
),
Hundreds: Table(
{
val: "C",
key: "100"
},
{
val: "CC",
key: "200"
},
{
val: "CCC",
key: "300"
},
{
val: "CD",
key: "400"
},
{
val: "D",
key: "500"
},
{
val: "DC",
key: "600"
},
{
val: "DCC",
key: "700"
},
{
val: "DCCC",
key: "800"
},
{
val: "CM",
key: "900"
}
),
Thousands: Table(
{
val: "M",
key: "1000"
},
{
val: "MM",
key: "2000"
},
{
val: "MMM",
key: "3000"
}
)
}
},
With(
{
varThousands: Text(Mod(varNumber, 10000)-Mod(varNumber, 1000)),
varHundreds: Text((Mod(varNumber,1000)-Mod(varNumber,100))),
varTens: Text((Mod(varNumber,100)-Mod(varNumber, 10))),
varUnits: Text((Mod(varNumber,10)))
},
If(
varNumber > 0 And varNumber < 4000,
Concatenate(
LookUp(varRoman.Thousands, key=varThousands, val),
LookUp(varRoman.Hundreds, key=varHundreds, val),
LookUp(varRoman.Tens, key=varTens, val),
LookUp(varRoman.Units, key=varUnits, val)
)
)
)
)
Result
XIII |