formate of a Single type varable 
Author Message
 formate of a Single type varable

this should be a simple question but it bothered me a lot. the following
code is a part of my programe;

Dim SP as Single

....

SP=SP+0.02

...

when the variable SP is(should be) zero, I got an actually value like
9.9999999e-09, because I need to display this value, so I would like it
just display 0, also when I use a variable of single type, the value of
this variable always has a more numbers behind the decimal point than I
need, I want to know if there is a way to solve this problem, so that I can
get the value with the resolution I want. Thanks in advance for any help



Sat, 04 Aug 2001 03:00:00 GMT  
 formate of a Single type varable
Hello Jiang,

I have had the same problem and found a -dirty- way around it:

If you just want to have the granularity of 0.02 you might find it
convinient to use long values and devide by 100 / or multiply by 100
combined with type-casts (to not loose fractions)

This will give you exact the values you want to have.

I do this for money calculations and calculate always in "Pfennig" (smallest
german unit)
Later on I devide by 100 to get accurate "Deutsch-Mark" values.

Hope that helps
Ole

Quote:

>this should be a simple question but it bothered me a lot. the following
>code is a part of my programe;

>Dim SP as Single

>....

>SP=SP+0.02

>...

>when the variable SP is(should be) zero, I got an actually value like
>9.9999999e-09, because I need to display this value, so I would like it
>just display 0, also when I use a variable of single type, the value of
>this variable always has a more numbers behind the decimal point than I
>need, I want to know if there is a way to solve this problem, so that I can
>get the value with the resolution I want. Thanks in advance for any help



Sun, 05 Aug 2001 03:00:00 GMT  
 formate of a Single type varable
Jiang,

Comments inline.

Matthew



Quote:
> this should be a simple question but it bothered me a lot. the following
> code is a part of my programe;

> Dim SP as Single

> ....

> SP=SP+0.02

> ...

> when the variable SP is(should be) zero, I got an actually value like
> 9.9999999e-09,

check out http://support.microsoft.com/support/kb/articles/q42/9/80.asp

 because I need to display this value, so I would like it

Quote:
> just display 0, also when I use a variable of single type, the value of
> this variable always has a more numbers behind the decimal point than I
> need, I want to know if there is a way to solve this problem, so that I
can
> get the value with the resolution I want. Thanks in advance for any help

Consider using Long or Currency data-type, or format the output using
Format.


Sun, 05 Aug 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help: Enforce Date formate to MM-DD-YY?

2. Check Date formate

3. Q: query database by years in varable

4. Using an if statement on a object varable

5. How to check if a varable exists??

6. Max Single Type Number

7. Byte representation of single and double floating point types

8. Data Type Usage: Single vs Currency vs Decimal

9. Round Single Data Type to 2 decimal places

10. Variable with Single Data Type rounded to 2 decimal places

11. Crystal and Single data types

12. Creating multiple font types in a single Rich Text Box

 

 
Powered by phpBB® Forum Software