Probabilistic choice: Difference between revisions

→‎{{header|jq}}: simplify align_decimal
(→‎{{header|jq}}: simplify align_decimal)
Line 2,047:
def rpad($len): tostring | ($len - length) as $l | .+ ("0" * $l)[:$l];
 
# Input: a string of digits with up to one embedded "."
# Output: the corresponding string representation with exactly $n decimal digits but aligned at the period
def align_decimal($n):
tostring
Line 2,054:
| if $ix then capture("(?<i>[0-9]*[.])(?<j>[0-9]{0," + ($n|tostring) + "})") as {$i, $j}
| $i + ($j|rpad($n))
else . + ".0" |+ align_decimal("0" * $n)
end ;
 
Line 2,153:
heth : 63455.9 63348 0.18
</pre>
 
 
=={{header|Julia}}==
2,469

edits