OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

is TEXT(A1;"#########0') broken?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
bertram
Power User
Power User


Joined: 13 Nov 2005
Posts: 55

PostPosted: Sat Sep 22, 2007 9:37 pm    Post subject: is TEXT(A1;"#########0') broken? Reply with quote

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
View user's profile Send private message
David
Super User
Super User


Joined: 24 Oct 2003
Posts: 5668
Location: Canada

PostPosted: Sun Sep 23, 2007 6:13 am    Post subject: Re: is TEXT(A1;"#########0') broken? Reply with quote

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
View user's profile Send private message
keme
Moderator
Moderator


Joined: 30 Aug 2004
Posts: 2910
Location: Egersund, Norway

PostPosted: Sun Sep 23, 2007 2:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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