Numerical and alphabetical suffixes: Difference between revisions
Numerical and alphabetical suffixes (view source)
Revision as of 11:33, 28 October 2018
, 5 years ago→{{header|Perl 6}}: Handle input numbers with commas correctly, add a demo of mixing named and factorial suffixes
Thundergnat (talk | contribs) m (Numbers not search engines.) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Handle input numbers with commas correctly, add a demo of mixing named and factorial suffixes) |
||
Line 138:
=={{header|Perl 6}}==
{{works with|Rakudo|2018.09}}
Scientific notation, while supported in Perl 6, is limited to IEE-752 64bit accuracy so there is some rounding on values using it. It would certainly be possible to implement a custom high accuracy conversion routine but I can't really see the point.
Unfortunately, this routine is almost useless for practical everyday use. It focuses on handling excessively large and archaic units (googol, greatgross) and completely ignores or makes unusable (due to forcing case insensitivity) many common current ones: c(centi), m(milli), μ(micro). Ah well.
<lang perl6><PAIRs 2 SCOres 20 DOZens 12 GRoss 144 GREATGRoss 1728
Line 165 ⟶ 167:
sub units (Str $str) {
$str.fc ~~ /^(.+?)(<alpha>*)('!'*)$/;
my ($val, $unit, $fact) =
$val.=subst(',', '', :g);
my @suf = $unit;
unless %suffix{$unit}:exists {
Line 171 ⟶ 174:
@suf = $0;
}
my $ret = $val<>;
if @suf[0] {
$ret = [*] $
}
if $fact.chars {
$ret = [*] ($
}
$ret
}
<2greatGRo 24Gros 288Doz
25.123kK 25.123m 2.5123e-00002G
25.123kiKI 25.123Mi 2.5123e-00002Gi +.25123E-7Ei
-.25123e-34Vikki 2e-77gooGols
9! 9!! 9!!! 9!!!! 9!!!!! 9!!!!!! 9!!!!!!! 9!!!!!!!! 9!!!!!!!!!
.017k!!>;</lang>
{{out}}
<pre> 2greatGRo: 3,456
24Gros: 3,456
288Doz: 3,456
172.8SCOre: 3,456
+1.567k: 1,567
0.1567e-2m: 1,567
Line 215 ⟶ 218:
9!!!!!!!: 18
9!!!!!!!!: 9
9!!!!!!!!!: 9
.017K!!: 34,459,425</pre>
=={{header|REXX}}==
|