+ Reply to Thread
Results 1 to 12 of 12

Convert any number to 3 digit only

  1. #1
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Convert any number to 3 digit only

    What UDF (Excel 2003 and above) i should have in my Personal Workbook, so that this function can be accessible across any workbook or VBA code, which can only be used in a specific workbook

    I need a UDF (User Defined Function) or VBA Code that can convert any numerical value, to ONLY 3 digit

    Example - Input or Cell A1 value is

    1 should be 100

    1.301 should be 130

    74650 should be 746

    12.658 should be 126, and so on.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Convert any number to 3 digit only

    If you want 12.658 to be converted to 126
    =INT(10^(2+MOD(LOG(A1), 1)))

    If you want 12.658 to be converted to 127
    =ROUND(10^(2+MOD(LOG(A1), 1)), 0)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Convert any number to 3 digit only

    Hi analystbank,

    Try this UDF:

    Please Login or Register  to view this content.
    You take any number and multiply it by 100 or 100000. Then you concatenate a blank space on the end of it. This turns the number into a string of letters.
    Then you take the left three letters in this text string and add zero to it. This turns it back into a number and your answer.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Convert any number to 3 digit only

    Row\Col
    A
    B
    C
    1
    1
    100
    B1: =--LEFT(1000000000000000*A1, 3)
    2
    1.301
    130
    3
    74650
    746
    4
    12.658
    126
    Last edited by shg; 02-01-2016 at 02:15 AM.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Convert any number to 3 digit only

    How about this?

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Convert any number to 3 digit only

    Thanks to all for such prompt reply suggesting formula, as well as UDF.

    @mgs73, only one suggestion to your UDF, it treats the result as Text only, and not numeric values, whereas that in case of MarvinP solution, the outcome, resultant value also behaves like number/numeric value.

    Thanks to all. This thread can be considered as solved.

  7. #7
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Convert any number to 3 digit only

    it treats the result as Text only, and not numeric values
    Actually, I thought that's what it would do - but when I tested it, Excel converted them to numbers.

  8. #8
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Convert any number to 3 digit only

    Trust, no offence here.

    What if i want to have 3 digit as above (Post #3), but want to conver numeric number after 3 (whatever length) to decimal, like

    1.301 should be 130.1

    74650 should be 746.50

    12.658 should be 126.58, and so on.

    I tried changing - NumStr As String to NumStr as Long but no success
    Last edited by analystbank; 04-15-2016 at 12:57 AM.

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Convert any number to 3 digit only

    Try
    =10^(2+MOD(LOG(A1),1))

  10. #10
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Convert any number to 3 digit only

    @mikerickson, Thanks . How to make UDF (User Defined function of it).

    I am just trying to create of UDF using your formula example but not able to create an UDF
    Last edited by analystbank; 04-22-2016 at 06:07 AM.

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Convert any number to 3 digit only

    Try
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Convert any number to 3 digit only

    Thanks, a ton, Sir (mikerickson)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. convert to 2 digit number
    By pilotwings64 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-17-2019, 03:16 AM
  2. Convert 3 digit or 4 digit number to time format
    By dubcap01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2015, 04:30 AM
  3. [SOLVED] Want to convert date to an 8 digit number
    By ppilot in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-17-2015, 06:26 PM
  4. [SOLVED] Convert number to two digit
    By mattress58 in forum Excel General
    Replies: 2
    Last Post: 10-29-2014, 10:10 AM
  5. Convert 4-5 digit number to time HH:MM:SS
    By scaffdog845 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-19-2012, 01:53 PM
  6. convert 9 digit number into day and time
    By cords in forum Excel General
    Replies: 7
    Last Post: 03-17-2012, 12:45 AM
  7. [SOLVED] convert a nine digit number to base 32
    By Wildman in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 01-17-2005, 10:06 PM

Tags for this Thread

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