Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1859

Re: Print formated strings

From Ray Koopman <koopman@sfu.ca>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Print formated strings
Date 2011-04-24 12:26 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ip14t4$ggb$1@smc.vnet.net> (permalink)
References <iouefo$6jp$1@smc.vnet.net>

Show all headers | View raw


On Apr 23, 4:51 am, =A9er=FDch Jakub <Ser...@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

Back to comp.soft-sys.math.mathematica | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Print formated strings Šerých Jakub <Serych@panska.cz> - 2011-04-23 11:51 +0000
  Re: Print formated strings Ray Koopman <koopman@sfu.ca> - 2011-04-24 12:26 +0000

csiph-web