Re: std.format add dash separators to large numbers
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
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
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
I meant underscores not dashes.
Re: std.format add dash separators to large numbers
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
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