# encoding: ascii # api: powershell # title: get-roman # description: Short powershell module to convert numbers to Roman numerals # version: 0.1 # type: function # author: Luis C # license: CC0 # function: get-roman # x-poshcode-id: 6818 # x-archived: 2017-04-08T01:01:46 # x-published: 2017-03-24T19:53:00 # # function get-roman ([int]$myNum) { if ($myNum -ge 4000 -or $myNum -le 0) { "$myNum is not a good one" } else { $myRomans = [Ordered]@{ M=1000;CM=900;D=500;CD=400;C=100;XC=90;L=50;XL=40;X=10;IX=9;V=5;IV=4;I=1 } foreach ($key in $myRomans.Keys) { while ($myNum -ge $myRomans.item($key)) { $myOut += $key; # build Roman numeral $myNum -= $myRomans.item($key) # subtract value from given number } } $myOut } }