Re: std.format add dash separators to large numbers

2011-08-17 Thread bearophile
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


Re: std.format add dash separators to large numbers

2011-08-17 Thread Jouko Koski

Andrej Mitrovic andrej.mitrov...@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



std.format add dash separators to large numbers

2011-08-16 Thread Andrej Mitrovic
Can format do something like this yet?

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

%s would have to be replaced with something else, obviously.


Re: std.format add dash separators to large numbers

2011-08-16 Thread Andrej Mitrovic
I meant underscores not dashes.


Re: std.format add dash separators to large numbers

2011-08-16 Thread bearophile
Andrej Mitrovic:

 Can format do something like this yet?
 
 auto str = format(%s, 100);
 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


Re: std.format add dash separators to large numbers

2011-08-16 Thread Jouko Koski

bearophile bearophileh...@lycos.com wrote:

Andrej Mitrovic:

auto str = format(%s, 100);
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