August 17, 2011
Can format do something like this yet?

auto str = format("%s", 1000000);
assert(str == "1_000_000");

%s would have to be replaced with something else, obviously.
August 17, 2011
Andrej Mitrovic:

> Can format do something like this yet?
> 
> auto str = format("%s", 1000000);
> assert(str == "1_000_000");
> 
> %s would have to be replaced with something else, obviously.

I suggest to add such formatter/function to Phobos.

Bye,
bearophile
August 17, 2011
"bearophile" <bearophileHUGS@lycos.com> wrote:
> Andrej Mitrovic:
>> auto str = format("%s", 1000000);
>> assert(str == "1_000_000");
> I suggest to add such formatter/function to Phobos.

While 1_000_000 may be the right thing in program code, the outside world would probably like to have numbers printed out according to their locale conventions. This is even more important with floating point or monetary values.

So before just adding some formatter to Phobos, I think that such formatter's use cases should be considered quite carefully.

-- 
Jouko

August 17, 2011
Jouko Koski:

> While 1_000_000 may be the right thing in program code, the outside world would probably like to have numbers printed out according to their locale conventions. This is even more important with floating point or monetary values.
> 
> So before just adding some formatter to Phobos, I think that such formatter's use cases should be considered quite carefully.

You are right, of course. On the other hand I don't think there are locales where the right way to print number is with underscores. But often I do want to print large numbers with underscores every three digits. So maybe your idea doesn't help me much.

Bye,
bearophile
August 17, 2011
Okay but I wasn't really thinking about locales, underscores between digits is a D syntax feature and it makes numbers more readable.
August 17, 2011
"Andrej Mitrovic" <andrej.mitrovich@gmail.com> kirjoitti:
> Okay but I wasn't really thinking about locales, underscores between
> digits is a D syntax feature and it makes numbers more readable.

I agree that using almost any (thousand) separator can make reading long numeric strings easier. I would still consider not exporting D's internal syntactical construct to outside world where it is never used that way. I do not favor any solution which is D-specific or suitable for insular Yankees only.

This sort of wrestling has already carried out in the past. For instance, the C90 standard work was prolonged by about a year because of adding the <locale.h> features that international community required. D can utilize maybe brighter technical solution, but still: No D-specific solutions and no localization as afterthought, please!

-- 
Jouko

Top | Discussion index | About this forum | D home