Floating Point DocVariable

S

SeanP

I have a DocVariable that I want to always show up with a Decimal. As of now
it cuts the decimal when it is a whole number. I didn't see a way to set it
to a floating point number or anything. How can I accomplish this? It has
to be simple, I am jsut not seeing it.
 
J

Jay Freedman

I have a DocVariable that I want to always show up with a Decimal. As of now
it cuts the decimal when it is a whole number. I didn't see a way to set it
to a floating point number or anything. How can I accomplish this? It has
to be simple, I am jsut not seeing it.

In the DocVariable field in the document, include a numeric picture
(\#) switch with the desired number of decimal places. For example, if
you want two digits after the decimal point, the field code should
look like

{ DocVariable MyVarName \#"0.00" }
 
S

SeanP

Oh yeah, but I am also trying to reference the DocVariable in a UserForm as
well, any way to make it show up in a textbox correctly formatted as well?
 
J

Jay Freedman

Hi Sean,

Yeah, it's simple if you know what to look for. The Format function in VBA
does the same trick as the picture switch in a field:

Dim ActualVar As String
ActualVar = ActiveDocument.Variables("MyVarName").Value
TextBox1.Text = Format(ActualVar, "0.00")
 
S

SeanP

That worked great, thanks so much. It actually turned out I needed both
methods. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top