Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #1850 > unrolled thread
| Started by | Šerých Jakub <Serych@panska.cz> |
|---|---|
| First post | 2011-04-23 11:51 +0000 |
| Last post | 2011-04-24 12:26 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
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
| From | Šerých Jakub <Serych@panska.cz> |
|---|---|
| Date | 2011-04-23 11:51 +0000 |
| Subject | Print formated strings |
| Message-ID | <iouefo$6jp$1@smc.vnet.net> |
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
[toc] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2011-04-24 12:26 +0000 |
| Message-ID | <ip14t4$ggb$1@smc.vnet.net> |
| In reply to | #1850 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web