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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Single/double data types

Status
Not open for further replies.

rdnzl

Programmer
Nov 22, 2002
5
NO
Hi there!
Will you please try the following code, and tell me why this works:
Dim sngMin As Single
Dim sngMax As Single
Dim sngRes As Single
sngMin = 145
sngMax = 1440
sngRes = sngMin / sngMax (=0,1006944)

But not this:
sngMin = 143
sngMax = 1440
sngRes = sngMin / sngMax (=9,930556E-02)

TIA
Jens
 
Hi Jens,

Both calculations produce correct results. The answers are just displayed in different formats. 9.930556E-02 means 9.930556 * 10^-2 (or 0.09930556); this is a number expressed in 'standard form' with a mantissa (the number before the E) between 1 and 10 and an exponent (the number after the E) being the power of 10 by which the mantissa must be multiplied in order to produce the answer.

I do not know what rules determine how a number is displayed by default but you can format both the above in any way you want. After the calculations if you display sngRes in a msgbox you will get what you show. If, instead, you display Format(sngRes,"0.00000000") in a msgbox you will get, respectively, 0.10069440 and 0.09930556.

Enjoy,
Tony
 
When you say doesn't work just what do you mean. They are both returning to you the correct answers. If you move the decimal place 2 spaces to the left on the second answer which is what the E-02 means it returns .09930556. I believe it returns as many digits as can be rounded and then uses the E-02 or Exponential function to display as many characters as possibile. A double of the same division gives you the same basic answer but with more precision(more digits) 9.93055555555556E-02 .

Hope this helps you understand.



Bob Scriver

Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
To both of you, thank you.

Yes, I do understand it, but I was a little confused at the moment :)
I don't know why Access (both '97 and 2002) displays the result in that way...

Jens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top