+ Reply to Thread
Results 1 to 9 of 9

Set decimal places by cell value

  1. #1
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Set decimal places by cell value

    I am converting values from SAE to Metric and wish to retain the decimal places of the SAE value before converting. My code below converts nicely but doesnt maintain decimal places.

    Please Login or Register  to view this content.
    Any hints, tips and or examples are appreciated.
    Last edited by Rick_Stanich; 06-23-2009 at 09:53 AM.
    Regards

    Rick
    Win10, Office 365

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

    Re: Set decimal places by cell value

    Dunno about SAE to metric, but I see you're converting inches to millimeters.

    If the cells are formatted as General, they have no fixed number of decimals, and so will the results. If they are formatted to have some fixed number of decimals, the results will have the same number.

    So ... what are you trying to do?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Re: Set decimal places by cell value

    In my world, SAE is inch.
    If the value of A1 is "1.000" then after I convert I want the new metric value to be "#.###" (3 decimals).
    If the Value of A1 is "1.00" then after I convert I want the new metric value to be "#.##" (2 decimals).
    And so on.

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

    Re: Set decimal places by cell value

    If they are formatted that way beforehand, your code won't change them.

    However,

    EDIT2:
    Please Login or Register  to view this content.
    Last edited by shg; 06-22-2009 at 04:42 PM.

  5. #5
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Re: Set decimal places by cell value

    Quote Originally Posted by shg View Post
    If they are formatted that way beforehand, your code won't change them.
    This is what I thought as well, but it is not the case. My 2 decimal values become 3, 3 becomes 4, etc...

    Edit: this isnt true. It seems random.

    The cells are formatted as General.
    Last edited by Rick_Stanich; 06-22-2009 at 04:44 PM.

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

    Re: Set decimal places by cell value

    General displays all the non-zero decimals within the space available. Try the revised code posted below.

  7. #7
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Re: Set decimal places by cell value

    Works great, Im just going to study this and figure out what you did!

    Thank you.
    Last edited by shg; 06-22-2009 at 04:50 PM.

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

    Re: Set decimal places by cell value

    Mark us up as Solved?

  9. #9
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Re: Set decimal places by cell value

    oops...

+ 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