| View previous topic :: View next topic |
| Author |
Message |
bertram Power User

Joined: 13 Nov 2005 Posts: 52
|
Posted: Sat Sep 22, 2007 9:37 pm Post subject: is TEXT(A1;"#########0') broken? |
|
|
I need to write Fortran-type fixed column data strings
I prefer spaces to separate columns instead of leading-0's
Is it possible?
| Code: | A1(a number cell) contains the value -123456 (a number)
=TEXT(A1;"0") works as described >> "-123456"
=TEXT(A1;"+0;-0") works as described >> "-123456"
=TEXT(A1;"0000000000") works as described >> "-000123456"
=TEXT(A1;"#########0") is broken, i.e. >> "-123456" (len=7, should be 10)
=TEXT(A1;" 0") is broken, i.e. >> "-123456" (len=7, should be 18)
=TEXT(A1;"#####0000000000") is broken, i.e. >> "-0000123456" (len=11, should be 15) |
Is there a way to left pad with spaces using a format string in a TEXT function?? |
|
| Back to top |
|
 |
David Super User


Joined: 24 Oct 2003 Posts: 5668 Location: Canada
|
Posted: Sun Sep 23, 2007 6:13 am Post subject: Re: is TEXT(A1;"#########0') broken? |
|
|
| bertram wrote: | | Is there a way to left pad with spaces using a format string in a TEXT function?? |
Yes; related to an old programming trick: Have a distant cell [E1] contain [filled with] a series of the space character. Then, in B1, have this, supposing that you want the length of string to be 10:
=CONCATENATE(LEFT(E1;10 - LEN(A1));A1)
I must admit some difficulty picturing exactly what you need though from your description. You can separate items with an intermediate empty column of width of your own choice.
David. |
|
| Back to top |
|
 |
keme Moderator


Joined: 30 Aug 2004 Posts: 2732 Location: Egersund, Norway
|
Posted: Sun Sep 23, 2007 2:54 pm Post subject: |
|
|
Not with a format string, as far as I can see. It's possible with a formula, though.
David's formula works nicely. A different approach, which I've used:
=REPT(" ";10-LEN(A1))&A1
Both are somewhat unforgiving when it comes to format overflow (unlike the spreadsheet format codes). David's solution will return the last n digits without any error indication, while mine will return an error code. What you prefer depends on your Fortran version, I guess...
And btw, the text function is not broken, though it may seem so to a Fortran programmer. As far as I can see from documentation, the format string is not intended to produce as rigid output as that of a Fortran format. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|