Formatting error for Lars

Sobel sobel at web.com
Fri Mar 21 02:14:38 PDT 2008


Ty Tower Wrote:

> You responded to one of my annoyances posts re birds on the roof .
> You wanted a page number for that example 
> 
> Page 131 and 132 deal with it in your book  
> Neither :C  nor :G seem to work 
> :G is the default and when I use {} its supposed to insert the 100
> I tried putting in the :G too
> 
> 
> module test;
> import tango.io.Stdout;
> import tango.text.locale.Locale;
>  
>  void main(){
>  Locale locale = new Locale;

Instantiating a Locale by itself isn't enough. You need to tell Stdout that you want localized output.

  Stdout.layout = new Locale;

>  Stdout("I have lost {:G} of my birds",20).newline;

I don't think the opCall syntax - Stdout() - supports formatting.

>  Stdout.formatln("I have {:C} birds on the roof",100);

Now it should work - but it will print something like:

  I have $100 birds on the roof

because C is the format specifier for currency. G is the default, and works regardless of the locale.

> }
> 
> 
> 
> [tytower at localhost tango]$  mystuff/test
> I have lost {} of my birds, 20
> I have {unknown format 'C'} birds on the roof
> 




More information about the Digitalmars-d mailing list