PoshCode Archive  Artifact Content

Artifact 89b3b993130be83ba715891f230f3f472d68ade0eb535454b0c28de27496b666:

  • File get-roman.ps1 — part of check-in [775576fcd9] at 2018-06-10 14:21:18 on branch trunk — Short powershell module to convert numbers to Roman numerals (user: Luis C size: 887)

# 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
    }
}