Commatizing numbers: Difference between revisions
Content added Content deleted
m (→{{header|D}}) |
|||
Line 250:
// The first number field begins with zero then no digit, or non-zero.
auto numField =
auto matchNum = matchFirst(scanSpan, numField);
Line 257:
// Pass only a point and capture a decimal fractional field, if any.
auto decField =
static if (smart) {
Line 276:
}
// There may be special prefixed formats that use different separators.
// Any format with a longer prefix should override a shorter one.
Tuple!(string, string)[] pairs;
▲ foreach (pair; specials.byPair) {
pairs ~= pair;
}
std.algorithm.sort!("a[0].length < b[0].length")(pairs);
foreach
symbol[0] == preAnyDigit[$ - symbol[0].length .. $])
ins = symbol[1];
}
}
Line 307 ⟶ 310:
assert("1000 2.3000".commatize == "1,000 2.3000");
assert("0001123.456789".commatize == "0001,123.456,789");
assert("Z$01000".commatize(0, 3, ",", ["Z$":" "]) == "Z$01 000");
}</lang>
{{out}}
|