[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-user
Subject:    RE: [groovy-user] Dynamic way to reference variables?
From:       "Bob Brown" <bob () transentia ! com ! au>
Date:       2009-09-30 23:09:31
Message-ID: 00c401ca4223$117c2e40$34748ac0$ () com ! au
[Download RAW message or body]

Whoops. Forgot the binary conversion...

Sorry.

BOB

> -----Original Message-----
> From: Bob Brown [mailto:bob@transentia.com.au]
> Sent: Thursday, 1 October 2009 8:55 AM
> To: user@groovy.codehaus.org
> Subject: RE: [groovy-user] Dynamic way to reference variables?
> 
> Um?
> 
> System.out.printf has been around since Java 1.5...
> 
> DecimalFormat has been around since at least 1.3, if dependencies are a
> worry...
> 
> //
> import java.text.*
> 
> printf "%08d\n", 3
> 
> def nf = new DecimalFormat("00000000")
> 
> println nf.format(3)
> //
> 
> Both are locale-aware and have locale-specific tweaks available.
> 
> Using NumberFormat _may_ be more efficient for repetitious work.
> 
> Cheers,
> 
> BOB
> 
> > -----Original Message-----
> > From: glaforge@gmail.com [mailto:glaforge@gmail.com] On Behalf Of
> > Guillaume Laforge
> > Sent: Thursday, 1 October 2009 12:39 AM
> > To: user@groovy.codehaus.org
> > Subject: Re: [groovy-user] Dynamic way to reference variables?
> >
> > This is becoming nicer and nicer :-)
> >
> > On Wed, Sep 30, 2009 at 16:34, Tim Yates <tim.yates@gmail.com> wrote:
> > > Or:
> > >
> > >       println Integer.toBinaryString( 3 ).padLeft( 8, "0" )
> > >
> > > (groovy)
> > >
> > > On Wed, Sep 30, 2009 at 2:50 PM, Francesco Pasqualini
> > <frapas@gmail.com>
> > > wrote:
> > >>
> > >>
> > >>
> >
>  System.out.println(String.format("%8s",Integer.toBinaryString(i)).repl
> > ace("
> > >> ","0"));
> > >>
> > >> On Mon, Sep 28, 2009 at 10:51 PM, Jay Pedersen
> > <jaypedersen@yahoo.com>
> > >> wrote:
> > >>>
> > >>> That is the main thing I am wondering about, and am curious
> > >>> in generate for better ways to display an integer in binary
> > >>> (I want 8 binary digits in all cases, I can't ask toBinaryString
> > >>> for that as far as I am aware, and at least in the past --
> > >>> you would get variable numbers of character output -- 0 was "0"
> > >>> and 3 was "11", etc.
> > >>>
> > >>> -Jay Pedersen
> > >>>
> > >>>
> > >>
> > >> (Java)
> > >> int i = 3;
> > >> String s
> = String.format("%8s",Integer.toBinaryString(i)).replace("
> > >> ","0");
> > >> System.out.println(s);
> > >>
> > >
> > >
> >
> >
> >
> > --
> > Guillaume Laforge
> > Groovy Project Manager
> > Head of Groovy Development at SpringSource
> > http://www.springsource.com/g2one
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic