ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   math (https://www.excelbanter.com/excel-programming/364703-math.html)

[email protected][_2_]

math
 
Hi, if, using a calculator i calculate 1 / 11 = 0.0909...... If in vba
I asign X as a variant, then x = 1 /11 then i get 9.090909......E-02.
Im fairly certain these answers are both the same, but as I enter x
into a cell Id like to display it as 0.0909.... Im thinking that Im not
declaring the variable correctly. Any Ideas.
Regards Robert


Jim Thomlinson

math
 
The two numbers are exactly the same. The only difference is the format of
the number. When you place the value in a worksheet or anywhere else you will
just need to format it to the way you want. That being said you really should
not be using variants (wherever possible). You probabaly want a Double in
this case.
--
HTH...

Jim Thomlinson


" wrote:

Hi, if, using a calculator i calculate 1 / 11 = 0.0909...... If in vba
I asign X as a variant, then x = 1 /11 then i get 9.090909......E-02.
Im fairly certain these answers are both the same, but as I enter x
into a cell Id like to display it as 0.0909.... Im thinking that Im not
declaring the variable correctly. Any Ideas.
Regards Robert



[email protected][_2_]

math
 
Thankyou foe your reply. That solves it in the worksheet. How would I
display it correctly in a msgBox.
Regards Robert







Jim Thomlinson wrote:

The two numbers are exactly the same. The only difference is the format of
the number. When you place the value in a worksheet or anywhere else you will
just need to format it to the way you want. That being said you really should
not be using variants (wherever possible). You probabaly want a Double in
this case.
--
HTH...

Jim Thomlinson


" wrote:

Hi, if, using a calculator i calculate 1 / 11 = 0.0909...... If in vba
I asign X as a variant, then x = 1 /11 then i get 9.090909......E-02.
Im fairly certain these answers are both the same, but as I enter x
into a cell Id like to display it as 0.0909.... Im thinking that Im not
declaring the variable correctly. Any Ideas.
Regards Robert




Jim Thomlinson

math
 
Assuming the value is in a Variable called MyVar

msgbox format(MyVar, "#,##0.000")
--
HTH...

Jim Thomlinson


" wrote:

Thankyou foe your reply. That solves it in the worksheet. How would I
display it correctly in a msgBox.
Regards Robert







Jim Thomlinson wrote:

The two numbers are exactly the same. The only difference is the format of
the number. When you place the value in a worksheet or anywhere else you will
just need to format it to the way you want. That being said you really should
not be using variants (wherever possible). You probabaly want a Double in
this case.
--
HTH...

Jim Thomlinson


" wrote:

Hi, if, using a calculator i calculate 1 / 11 = 0.0909...... If in vba
I asign X as a variant, then x = 1 /11 then i get 9.090909......E-02.
Im fairly certain these answers are both the same, but as I enter x
into a cell Id like to display it as 0.0909.... Im thinking that Im not
declaring the variable correctly. Any Ideas.
Regards Robert





Tom Ogilvy

math
 
Just to add to Jim's words, you can can find checking things out in the
immediate window is often helpful:

x = 1 /11
? x
9.09090909090909E-02
ActiveCell.Value = x
? activecell.Value
9.09090909090909E-02
? activecell.Text
0.090909

activecell.Offset(1,0).Select
ActiveCell.Formula = "=1/11"
? activecell.Value
9.09090909090909E-02
? activeCell.Text
0.090909


--
Regards,
Tom Ogilvy


" wrote:

Hi, if, using a calculator i calculate 1 / 11 = 0.0909...... If in vba
I asign X as a variant, then x = 1 /11 then i get 9.090909......E-02.
Im fairly certain these answers are both the same, but as I enter x
into a cell Id like to display it as 0.0909.... Im thinking that Im not
declaring the variable correctly. Any Ideas.
Regards Robert



[email protected][_2_]

math
 

Thankyou both for your replys. Very helpfull.
Regards Robert



All times are GMT +1. The time now is 12:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com