July 14, 2019 Substitutions with writef() or format()? | ||||
|---|---|---|---|---|
| ||||
'Morning, all.
If these lines:
string currency = format("$%,.02f", 11_234_456.99);
writeln(currency);
Will result in:
$11,234,456.99
Why don't these lines:
string notCurrency = format("%,", 11_234_456);
writeln(notCurrency);
result in:
11,234,456
???
Instead of a range violation?
| ||||
July 14, 2019 Re: Substitutions with writef() or format()? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ron Tarrant | On Sunday, 14 July 2019 at 13:45:38 UTC, Ron Tarrant wrote:
> 'Morning, all.
>
> If these lines:
>
> string currency = format("$%,.02f", 11_234_456.99);
> writeln(currency);
>
> Will result in:
>
> $11,234,456.99
>
> Why don't these lines:
>
> string notCurrency = format("%,", 11_234_456);
> writeln(notCurrency);
>
> result in:
>
> 11,234,456
>
> ???
>
> Instead of a range violation?
Never mind. This works:
string notCurrency = format("%,?d", ',', 11_234_456);
writeln(notCurrency);
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply