+ Reply to Thread
Results 1 to 4 of 4

[solved] convert variable length decimal to fixed string w/left and right padding

  1. #1
    Registered User
    Join Date
    10-31-2012
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003
    Posts
    2

    [solved] convert variable length decimal to fixed string w/left and right padding

    Hello,
    I need to convert a decimal to a fixed length 15 character string. The decimal varies in length, both to the left and right of the decimal. When converted to a sting, the right 8 characters represent the characters to the right of the decimal and the string cannot exceed 15 characters. Variable length padding is required on each side of the decimal.

    The first thought is create an UDF, that might be wrong. I've tried nesting various if, trim, find, contatenate, etc...and am honestly out of ideas.

    e.g. 1.23 converted to string is 000000123000000
    e.g. 1.234 converted to string is 000000123400000
    e.g. 111.234 converted to string is 000011123400000

    Please help!
    Last edited by jayz2949; 10-31-2012 at 10:20 PM. Reason: [solved]

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: convert variable length decimal to fixed string w/left and right padding

    try this. you may have to add/subtract zero's to get it as you want it...

    =SUBSTITUTE(TEXT(A1,"00000000.0000000"),".","")
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    10-31-2012
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: convert variable length decimal to fixed string w/left and right padding

    That seems to pass various tests...many thanks for a quick response!!

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: [solved] convert variable length decimal to fixed string w/left and right padding

    you're welcome, and thanks for the rep

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1