Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Round variable to 4 decimal places

On Sun, 25 Sep 2005 05:55:01 -0700, "achidsey"
(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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Round variable to 4 decimal places

Hi Alan,

One way:

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


---
Regards,
Norman



"achidsey" (notmorespam) wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default 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" (notmorespam) wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default 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"
(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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i round a quotient to specific decimal places? gissineth Excel Worksheet Functions 3 March 4th 10 03:18 AM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
Entering numbers with variable decimal places. Jack Excel Worksheet Functions 8 February 2nd 05 04:35 AM
ROUND DATA TO 2 DECIMAL PLACES roy in sunbury New Users to Excel 1 January 12th 05 03:33 AM
variable as Currency two decimal places Max Bialystock Excel Programming 2 May 10th 04 10:48 PM


All times are GMT +1. The time now is 08:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"