+ Reply to Thread
Results 1 to 6 of 6

Round variable to 4 decimal places

  1. #1
    achidsey
    Guest

    Round variable to 4 decimal places

    Excel Experts,

    In my code, I create a variable that I later incorporate into a forumula I
    enter in a cell.

    I only want to enter the variable with four decimal places. How would I
    code this?

    For example, my code is similar to,

    Sub EnterBuyPrincipal( )

    Dim TPrice As Variant

    TPrice = 2220/850

    Range("A2").FormulaR1C1 = "=100*" & TPrice

    End Sub

    The way it is now, the code enters "=100*2.61176470588235". I'm not trying
    to change the number of decimals displayed, but rather the text of the
    formula. I want it to read "=100*2.6118".

    Thanks in advance,
    Alan


    --
    achidsey

  2. #2
    Ron Rosenfeld
    Guest

    Re: Round variable to 4 decimal places

    On Sun, 25 Sep 2005 05:55:01 -0700, "achidsey"
    <chidsey2@hotmail.com(notmorespam)> wrote:

    >Excel Experts,
    >
    >In my code, I create a variable that I later incorporate into a forumula I
    >enter in a cell.
    >
    >I only want to enter the variable with four decimal places. How would I
    >code this?
    >
    >For example, my code is similar to,
    >
    >Sub EnterBuyPrincipal( )
    >
    >Dim TPrice As Variant
    >
    >TPrice = 2220/850
    >
    >Range("A2").FormulaR1C1 = "=100*" & TPrice
    >
    >End Sub
    >
    >The way it is now, the code enters "=100*2.61176470588235". I'm not trying
    >to change the number of decimals displayed, but rather the text of the
    >formula. I want it to read "=100*2.6118".
    >
    >Thanks in advance,
    >Alan


    ========================
    Sub EnterBuyPrincipal()

    Dim TPrice As Variant

    TPrice = Round(2220 / 850, 4)

    Range("A2").FormulaR1C1 = "=100*" & TPrice

    End Sub
    ========================

    or

    ==========================
    Sub EnterBuyPrincipal()

    Dim TPrice As Variant

    TPrice = Application.WorksheetFunction.Round(2220 / 850, 4)

    Range("A2").FormulaR1C1 = "=100*" & TPrice

    End Sub
    =========================

    Check the MSKB for VBA Round vs Round worksheet function for the differences.
    The worksheet function does arithmetic rounding; the VBA Round does what is
    sometimes called "banker's rounding".




    --ron

  3. #3
    Norman Jones
    Guest

    Re: Round variable to 4 decimal places

    Hi Alan,

    One way:

    Range("A2").FormulaR1C1 = "=100*" & Round(TPrice, 4)


    ---
    Regards,
    Norman



    "achidsey" <chidsey2@hotmail.com(notmorespam)> wrote in message
    news:B00299A8-91A1-49D3-8E41-DA5A3EA2CA98@microsoft.com...
    > Excel Experts,
    >
    > In my code, I create a variable that I later incorporate into a forumula I
    > enter in a cell.
    >
    > I only want to enter the variable with four decimal places. How would I
    > code this?
    >
    > For example, my code is similar to,
    >
    > Sub EnterBuyPrincipal( )
    >
    > Dim TPrice As Variant
    >
    > TPrice = 2220/850
    >
    > Range("A2").FormulaR1C1 = "=100*" & TPrice
    >
    > End Sub
    >
    > The way it is now, the code enters "=100*2.61176470588235". I'm not
    > trying
    > to change the number of decimals displayed, but rather the text of the
    > formula. I want it to read "=100*2.6118".
    >
    > Thanks in advance,
    > Alan
    >
    >
    > --
    > achidsey




  4. #4
    achidsey
    Guest

    Re: Round variable to 4 decimal places

    Norman, Thanks for your help. Alan
    --
    achidsey


    "Norman Jones" wrote:

    > Hi Alan,
    >
    > One way:
    >
    > Range("A2").FormulaR1C1 = "=100*" & Round(TPrice, 4)
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "achidsey" <chidsey2@hotmail.com(notmorespam)> wrote in message
    > news:B00299A8-91A1-49D3-8E41-DA5A3EA2CA98@microsoft.com...
    > > Excel Experts,
    > >
    > > In my code, I create a variable that I later incorporate into a forumula I
    > > enter in a cell.
    > >
    > > I only want to enter the variable with four decimal places. How would I
    > > code this?
    > >
    > > For example, my code is similar to,
    > >
    > > Sub EnterBuyPrincipal( )
    > >
    > > Dim TPrice As Variant
    > >
    > > TPrice = 2220/850
    > >
    > > Range("A2").FormulaR1C1 = "=100*" & TPrice
    > >
    > > End Sub
    > >
    > > The way it is now, the code enters "=100*2.61176470588235". I'm not
    > > trying
    > > to change the number of decimals displayed, but rather the text of the
    > > formula. I want it to read "=100*2.6118".
    > >
    > > Thanks in advance,
    > > Alan
    > >
    > >
    > > --
    > > achidsey

    >
    >
    >


  5. #5
    achidsey
    Guest

    Re: Round variable to 4 decimal places

    Ron, Thanks for your help. Alan

    --
    achidsey


    "Ron Rosenfeld" wrote:

    > On Sun, 25 Sep 2005 05:55:01 -0700, "achidsey"
    > <chidsey2@hotmail.com(notmorespam)> wrote:
    >
    > >Excel Experts,
    > >
    > >In my code, I create a variable that I later incorporate into a forumula I
    > >enter in a cell.
    > >
    > >I only want to enter the variable with four decimal places. How would I
    > >code this?
    > >
    > >For example, my code is similar to,
    > >
    > >Sub EnterBuyPrincipal( )
    > >
    > >Dim TPrice As Variant
    > >
    > >TPrice = 2220/850
    > >
    > >Range("A2").FormulaR1C1 = "=100*" & TPrice
    > >
    > >End Sub
    > >
    > >The way it is now, the code enters "=100*2.61176470588235". I'm not trying
    > >to change the number of decimals displayed, but rather the text of the
    > >formula. I want it to read "=100*2.6118".
    > >
    > >Thanks in advance,
    > >Alan

    >
    > ========================
    > Sub EnterBuyPrincipal()
    >
    > Dim TPrice As Variant
    >
    > TPrice = Round(2220 / 850, 4)
    >
    > Range("A2").FormulaR1C1 = "=100*" & TPrice
    >
    > End Sub
    > ========================
    >
    > or
    >
    > ==========================
    > Sub EnterBuyPrincipal()
    >
    > Dim TPrice As Variant
    >
    > TPrice = Application.WorksheetFunction.Round(2220 / 850, 4)
    >
    > Range("A2").FormulaR1C1 = "=100*" & TPrice
    >
    > End Sub
    > =========================
    >
    > Check the MSKB for VBA Round vs Round worksheet function for the differences.
    > The worksheet function does arithmetic rounding; the VBA Round does what is
    > sometimes called "banker's rounding".
    >
    >
    >
    >
    > --ron
    >


  6. #6
    Registered User
    Join Date
    01-09-2014
    Location
    guatemala
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Round variable to 4 decimal places

    Thanks for your help

+ 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