Value to portuguese

Run Settings
LanguageRaku
Language Version
Run Command
multi value-to-portuguese(1) {"um real"} multi value-to-portuguese(Int $value) { "{ .trim } reais" with value-to-portuguese |$value.comb.reverse } multi value-to-portuguese(Rat $value) { my @cents = ($value % 1 * 100).comb; @cents.push: |("0" xx 2 - @cents); ( value-to-portuguese($value.Int).trim, |("$_ centavos" with dezena |@cents) ).join: " e " } multi unidade("0") { Empty } multi unidade("1") {"um"} multi unidade("2") {"dois"} multi unidade("3") {"três"} multi unidade("4") {"quatro"} multi unidade("5") {"cinco"} multi unidade("6") {"seis"} multi unidade("7") {"sete"} multi unidade("8") {"oito"} multi unidade("9") {"nove"} multi dezena("0", "0") { Empty } multi dezena("0", $u) { unidade($u) } multi dezena("1", "0") {"dez"} multi dezena("1", "1") {"onze"} multi dezena("1", "2") {"doze"} multi dezena("1", "3") {"treze"} multi dezena("1", "4") {"quatorze"} multi dezena("1", "5") {"quinze"} multi dezena("1", "6") {"desesseis"} multi dezena("1", "7") {"desessete"} multi dezena("1", "8") {"desoito"} multi dezena("1", "9") {"desenove"} multi dezena("2", "0") {"vinte"} multi dezena("3", "0") {"trinta"} multi dezena("4", "0") {"quarenta"} multi dezena("5", "0") {"cinquenta"} multi dezena("6", "0") {"sessenta"} multi dezena("7", "0") {"setenta"} multi dezena("8", "0") {"oitenta"} multi dezena("9", "0") {"noventa"} multi dezena(Str $d, Str $u) {join " e ", dezena($d,"0"), unidade($u)} multi centena("0", "0", "0") { Empty } multi centena("0", $d, $u) { dezena($d, $u) } multi centena("1", "0", "0") {"cem"} multi centena("2", "0", "0") {"duzentos"} multi centena("3", "0", "0") {"trezentos"} multi centena("4", "0", "0") {"quatrocentos"} multi centena("5", "0", "0") {"quinhentos"} multi centena("6", "0", "0") {"seiscentos"} multi centena("7", "0", "0") {"setecentos"} multi centena("8", "0", "0") {"oitocentos"} multi centena("9", "0", "0") {"novecentos"} multi centena("1", Str $d, Str $u) {join " e ", "cento", dezena($d, $u)} multi centena(Str $c, Str $d, Str $u) { join " e ", centena($c, "0", "0"), dezena($d, $u)} multi value-to-portuguese("0") {"zero"} multi value-to-portuguese("1", *@rest, :mil($) where {.defined && $_ eq "1"}) { mil @rest } multi value-to-portuguse("1", "0", "0", *@rest, :mil($) where {.defined && $_ eq "1"}) { mil @rest } sub mil(@rest) { ( value-to-portuguese(|@rest), "mil" ).join: " " } multi value-to-portuguese(:$mil) { Empty } multi value-to-portuguese("0", "0", "0", *@rest, :$mil = 0) { value-to-portuguese |@rest, :mil($mil + 1) } multi value-to-portuguese(Str $u, Str $d="0", Str $c="0", *@rest, UInt :$mil = 0) { state @mil = "", "mil", <milhão milhões>, <bilhão bilhões>, <trilhão trilhões>; ( value-to-portuguese(|@rest, :mil($mil+1)), "{ centena($c, $d, $u) } { ($c == $d == 0 && $u == 1) ?? @mil[$mil].head !! @mil[$mil].tail }" ).join: " " } for (0.1, 3.14, 10.98) -> $num { say value-to-portuguese($num) } for ^1000 -> $num { say value-to-portuguese($num) }
Editor Settings
Theme
Key bindings
Full width
Lines