MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Print formated strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118363] Re: Print formated strings
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Sun, 24 Apr 2011 08:26:20 -0400 (EDT)
  • References: <iouefo$6jp$1@smc.vnet.net>

On Apr 23, 4:51 am, =A9er=FDch Jakub <Ser... at panska.cz> wrote:
> Dear Mathgroup,
>
> I know, that it must have very easy solution, but I
> cannot find it :-(((
>
> My problem is to print numbers in the string form with predefined
> format. For example I have numbers:
>
> 60
> 123.678123
> 1.45 and
> 5846.123
>
> And I wanted the output:
> 0 060.000
> 0 123.678
> 0 001.450 and
> 5 846.123
>
> Which function is usable for such formating. I came through the ToString,
> Print, Format, StringForm and StringFormat in the help, I was trying to
> use all "See Also" references, but I cannot find it...
>
> Thank for help
>
> Jakub

numbers = {60, 123.678123, 1.45, 5846.123};

This should work, but doesn't:

Scan[Print@NumberForm[#,{7,3}, NumberPadding->{"0","0"},
     DigitBlock->3, NumberSeparator->" "]&, numbers]

000060.000
000123.678
000001.450
05 846.123

Here's an ad hoc workaround:

Scan[Print@StringInsert[StringTake[ToString@NumberForm[#,{7,3},
     NumberPadding->{"0","0"}], -8], " ", 2]&, numbers]

0 060.000
0 123.678
0 001.450
5 846.123


  • Prev by Date: Re: Limit[f[x], x->a] vs. f[a]. When are they equal?
  • Next by Date: Re: How to roll up multiple Line calls into a loop
  • Previous by thread: Print formated strings
  • Next by thread: Re: Print formated strings