Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maths Problem

Status
Not open for further replies.

kennedymr2

Programmer
May 23, 2001
594
0
0
AU
I have a query (maths) in vb6

in Dos and excel i get the correct results but
in vb6, i have a problem.

if i.....
MsgBox (1 / 14.7) result 6.80272.... etc ... -02
this should be .068027 etc
MsgBox (1 / 8.9) result .11235 all ok

Really appreciate some help

Regards Kennedymr2


 
I have done some more testing...
if i MsgBox (Format(1 / 14.7, "###.#########"))it seems all ok..

??? is this the solution, or is there a better way ????

Regards kennedymr2
 



Hi,

Did you notice the 6.802....E-2

There's your answer!

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
??What exactly is the E-2 ?????

Is there another way of handling the problem..
 
scientific notation.

When you display the number to the user, format is your friend.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Many thanks for the help......SkipVought and gmmastros

Never struck the problem in the past... maybe i never need to display before...
 
I would in general not do the math operations inside the MsgBox function. Do the operations first and stick the results in a variable. If you want to be sure of how the answer is presented, put it in a string variable and then use the Format function to change how it is displayed. Then put the variable in the MsgBox.
 
You can also convert your result to Decimal data type which refrains from using the scientific notation.
[tt]
MsgBox CDec(1 / 14.7)[/tt]
-or-
[tt]Dim V As Variant
V = CDec(1 / 14.7)
MsgBox V[/tt]
 
Really appreciate the help offered.

I now understand this area a lot better now.

I am now doing all calculations fully , and then only formatting the result.


Thanks everyone again

regards kennedymr2
 
when doing multiplication and division

ensure that all variables are of the same type

or vaiable results ensue

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top