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

Convert Double to Decimal 1

Status
Not open for further replies.

bytehead

Programmer
Jul 12, 2001
25
0
0
US
I need to convert Double to Decimal as such:

1234 / 1000 = 1.234

I am at a loss. This has to be easy to do...

Thanks,
Brian
 
Brian,

Did you mean convert a WHOLE NUMBER, as 1234, (Integer or Long, with implied decimal places), to Double?

You seem to have nailed the concept for 3 places!

Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
OK, I found the CDec datatype, but it can only be used with a datatype of variant. Well I had my variable declared as double and it was not working because of that.

All is well now.

Thanks!
 
Code:
   Dim n As Double, m As Variant
   n = 1.234
   MsgBox m & ":" & VarType(m)
   m = CDec(n)
   MsgBox m & ":" & VarType(m)

Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
Skip,

Excately what I used, but now I am faced with when I divide a number like 10000 / 1000 = 10 not 10.000 as I need.

Is there a way to format the decimal so it is always three decimal places even if it is a whole number?

Thanks,
Brian
 
That is not a variable type issue. It's a FORMAT issue for display purposes ONLY.

For instance...
Code:
   Dim m As Variant
   m = CDec(10000 / 1000)
   MsgBox m
   MsgBox Format(m, "0.000")



Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
Skip,

Just what I was looking for! Life Saver for the day, and a pat on your back.

Thanks.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top